简体   繁体   中英

Build request with IP address

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM