Shell脚本-强制在curl,nc或telnet中进行HTTP 1.1流水线操作

问题描述 投票:0回答:1

我需要force在bash脚本上使用curl,telnet或netcat对服务器GET请求进行HTTP管道传输(1.1)。我已经尝试使用curl进行此操作,但是到目前为止as I know该工具自7.65.0版以来已经放弃了HTTP流水线支持,但是我找不到有关该操作的更多信息。不过,如果无法使用telnet或netcat,我可以在其他计算机上访问curl版本7.29.0。

bash http curl telnet netcat
1个回答
0
投票

来自维基百科:

HTTP流水线技术是在单个TCP(传输控制协议)连接上发送多个HTTP请求而无需等待相应响应的技术。

要使用netcat发送多个GET请求,应采用以下方法:

echo -en "GET /index.html HTTP/1.1\r\nHost: example.com\r\n\r\nGET /other.html HTTP/1.1\r\nHost: example.com\r\n\r\n" | nc example.com 80

这将向example.com发送两个HTTP GET请求,一个用于http://example.com/index.html,另一个用于http://example.com/other.html

-e标志表示解释转义序列(回车和换行符,或\ r和\ n)。 -n表示不要在末尾打印换行符(如果没有-n,它可能会工作)。

我刚刚运行了上面的命令,并从中得到了两个响应,一个是200 OK,另一个是404 Not Found。

如果您执行HEAD请求而不是GET请求,则可能更容易查看多个请求和响应。这样,example.com的服务器将只响应标头。

echo -en "HEAD /index.html HTTP/1.1\r\nHost: example.com\r\n\r\nHEAD /other.html HTTP/1.1\r\nHost: example.com\r\n\r\n" | nc example.com 80

这是我从上面的命令获得的输出:

$ echo -en "HEAD /index.html HTTP/1.1\r\nHost: example.com\r\n\r\nHEAD /other.html HTTP/1.1\r\nHost: example.com\r\n\r\n" | nc example.com 80
HTTP/1.1 200 OK
Content-Encoding: gzip
Accept-Ranges: bytes
Age: 355429
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Mon, 24 Feb 2020 14:48:39 GMT
Etag: "3147526947"
Expires: Mon, 02 Mar 2020 14:48:39 GMT
Last-Modified: Thu, 17 Oct 2019 07:18:26 GMT
Server: ECS (dna/63B3)
X-Cache: HIT
Content-Length: 648

HTTP/1.1 404 Not Found
Accept-Ranges: bytes
Age: 162256
Cache-Control: max-age=604800
Content-Type: text/html; charset=UTF-8
Date: Mon, 24 Feb 2020 14:48:39 GMT
Expires: Mon, 02 Mar 2020 14:48:39 GMT
Last-Modified: Sat, 22 Feb 2020 17:44:23 GMT
Server: ECS (dna/63AD)
X-Cache: 404-HIT
Content-Length: 1256

如果要查看更多详细信息,请在wireshark运行时运行以下命令之一。该请求在第7号(突出显示)中发送,并且在第11号和第13号上接收到两个响应。screenshot of wireshark

© www.soinside.com 2019 - 2024. All rights reserved.