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

查看:58
本文介绍了如何使用 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 get 请求的任何好的教程,所以我将其发布在这里.

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 isn't​‎​‎ worth the effort.

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

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

nc -l 64738

(有时 nc -l -p 64738 是正确的参数列表)

(Sometimes nc -l -p 64738 is the correct argument list)

...然后使用真正的浏览器向该端口发出浏览器请求.只需在浏览器中输入 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: 标头,如您在我的示例中所见.这是因为多个网站可以运行在同一个网络服务器上,所以浏览器需要告诉他,它想从哪个网站加载页面.

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天全站免登陆