如何使用netcat手动发出HTTP GET请求? [英] How to make an HTTP GET request manually with netcat?

查看:371
本文介绍了如何使用netcat手动发出HTTP GET请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

假设我想找回坎普尔的.

Let's assume I want to retrieve of Kanpur's.

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

How to make an HTTP GET request with Netcat?

我正在做这样的事情.

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

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

I don't know exactly if I'm even in the right direction or not. I am not able to find any good tutorials on how to make an HTTP get request with netcat, so I'm posting it on here.

推荐答案

当然,您可以挖掘搜索google的标准,但是实际上,如果您只想获得一个URL,那就不值得了.

Of course you could dig in standards searched for google, but actually if you want to get only a single URL, it doesn't worth the effort.

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

You could also start a netcat in listening mode on a port:

nc -l 64738

...,然后使用真实的浏览器向该端口发出浏览器请求.只需在浏览器中输入http://localhost: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.解决方案很简单:

In your actual case the problem is that HTTP/1.1 doesn't close the connection automatically, but it waits your next URL you want to retrieve. The solution is simple:

使用HTTP/1.0:

Use HTTP/1.0:

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

或使用Connection:请求标头说出您要在此之后关闭的服务器:

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>

扩展名:在GET标头之后,仅写入请求的路径部分.您要从中获取数据的主机名属于Host:标头,如您在我的示例中所见.这是因为多个网站可以在同一台Web服务器上运行,因此浏览器需要说出他想从哪个网站加载页面.

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 site it wants to load the page.

这篇关于如何使用netcat手动发出HTTP GET请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆