Build request with IP address

94 views Asked by At

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.

1

There are 1 answers

0
K. A. Buhr On

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.