且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-04-02 05:17:20

当然,您可以挖掘搜索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.