如何使用netcat手动发出HTTP GET请求?
收藏

因此,我必须从http://www.rssweather.com/dir/Asia/India从任何一个城市获取温度。

假设我要检索坎普尔的。

如何使用Netcat发出HTTP GET请求?

我正在做这样的事情。

nc -v rssweather.com 80
GET http://www.rssweather.com/wx/in/kanpur/wx.php HTTP/1.1

我不确定我是否朝着正确的方向前进。我找不到任何有关如何通过netcat发出HTTP获取请求的优秀教程,因此将其发布在此处。

最佳答案

当然,您可以挖掘搜索google的标准,但是实际上,如果您只想获得一个URL,则不值得付出努力。

您还可以在端口上以侦听模式启动netcat:

nc -l 64738

...and then do a browser request into this port with a real browser. Just type in your browser http://localhost:64738 and see.

在您的实际情况下,问题在于HTTP / 1.1不会自动关闭连接,但会等待您要检索的下一个URL。解决方案很简单:

使用HTTP / 1.0:

GET /this/url/you/want/to/get HTTP/1.0
Host: www.rssweather.com
<empty line>

or use a Connection: request header to say the server you want to close after that:

GET /this/url/you/want/to/get HTTP/1.1
Host: www.rssweather.com
Connection: close
<empty line>

Extension: After the GET header write only the path part of the request. The hostname from which you want to get data belongs to a Host: header as you can see in my examples. This is because multiple websites can run on the same webserver, so the browsers need to say him, from which server they want to load the page.

    公众号
    关注公众号订阅更多技术干货!