简体   繁体   English

使用IP地址建立请求

[英]Build request with IP address

I would like to know how to build a request with server's IP address (not URL). 我想知道如何使用服务器的IP地址(而不是URL)建立请求。

Actually I start with a given URL and then with the help of lenses rebuild the request: 实际上,我从给定的URL开始,然后借助镜头重新构建请求:

   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 . 从头开始创建Request时,这或多或少是您应该做的,除了有一个预定义的defaultRequest等效于http://localhost So, use: 因此,使用:

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

and I think you're doing it right. 我认为您做对了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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