gpt4 book ai didi

巴什 curl : Don't close connection in between requests when run sequentially

转载 作者:可可西里 更新时间:2023-11-01 15:11:56 26 4
gpt4 key购买 nike

我正在尝试编写一个 BASH 命令,该命令使用 CURL 向两个不同的网页发送 GET 请求,但使用相同的连接。对我来说,这就像向登录页面发送 GET 请求以向服务器进行身份验证,然后第二个请求模拟自动重定向到主页,这会在网络浏览器中发生(通过 meta 刷新标签)。我需要链接请求,因为主页的内容(由服务器生成)对于 guest 用户和经过身份验证的用户是不同的。

我首先根据 SOF post 的推荐尝试了这个命令(假设变量 $IP$PORT 已经定义了有效值):

curl -u user:pass ${IP}:${PORT}/login.php && curl ${IP}:${PORT}/index.php

但是,我总是在第一个 GET 结束和第二个 GET 开始之间发生这样的事情:

* Connection #0 to host 10.0.3.153 left intact
* Closing connection #0

那么 SOF 帖子是不是错了?无论如何,执行此命令将成功地保持两个请求之间的连接打开:

curl -u user:pass ${IP}:${PORT}/login.php ${IP}:${PORT}/index.php

但是,与后一个命令相比,我真的更喜欢更接近前一个命令的解决方案。主要原因是将第一页和第二页的输出分成两个不同的输出文件。所以我想做类似的事情:

curl page1.html > output1 && curl page2.html > output2

当然,我需要重用同一个连接,因为 page2.html 的内容取决于我也在同一个 HTTP session 中对 page1.html 发出请求。

我也愿意接受使用 netcat 或 wget 的解决方案,但不是 PHP!

最佳答案

根据 curl manual概要如下:

curl [选项] [URL...]

这意味着您可以在同一命令中依次指定多个 url。 Curl 将重用每个后续 url 的句柄:

curl will attempt to re-use connections for multiple file transfers, so that getting many files from the same server will not do multiple connects / handshakes. This improves speed. Of course this is only done on files specified on a single command line and cannot be used between separate curl invokes.

关于巴什 curl : Don't close connection in between requests when run sequentially,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15319770/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com