0

I would like to know how to build a request with server's IP address (not URL).

Actually I start with a given URL and then with the help of lenses rebuild the request:

   connect = do
        request' <- parseRequest "http://localhost"
        let request = setRequestMethod "POST"
                    $ setRequestHost (S8.pack ("xx.xxx.xxx.xxx"))
                    $ ... 

It works fine but it's inelegant, clumsy code.

user11228628
  • 1,526
  • 1
  • 6
  • 17
user3680029
  • 179
  • 8
  • 2
    What's wrong with `"http://xxx.xxx.xxx.xxx"`? – HTNW May 29 '19 at 15:37
  • Nthg. It just a placeholder – user3680029 May 29 '19 at 15:51
  • 4
    No, what's wrong with just passing your IP address into `parseRequest` instead of `localhost`, like `"http://xx.xxx.xxx.xxx"`? The `http://` should make it a valid URL. – user11228628 May 29 '19 at 15:58
  • You're right parsing with "http:// xx.xxx.xxx.xx" do the job, I was sure that I checked this without success but now it's working (strange, I messed surely something else at the time..) – user3680029 May 30 '19 at 04:45

1 Answers1

0

This is more or less what you're supposed to do when you create a Request from scratch, except there's a predefined defaultRequest equivalent to http://localhost. So, use:

request = setRequestMethod "POST"
        $ setRequestHost (S8.pack "xx.xxx.xxx.xxx")
        $ ... 
        $ defaultRequest

and I think you're doing it right.

K. A. Buhr
  • 45,621
  • 3
  • 45
  • 71