cURL:重用 TCP 连接时的多个 POST 请求

Pau*_*aul 8 linux curl

如果将多个 URL 传递给 cURL,它会在可能的情况下重用 TCP 连接。

例如:

curl -o 1.jpg http://example.com/1.jpg -o 2.jpg http://example.com/2.jpg
Run Code Online (Sandbox Code Playgroud)

我需要做同样的事情,但对同一个 URL 使用不同的帖子查询。

我想也许这会奏效:

curl -d "a=1" -o 1 http://example.com/script.php -d "a=2" -o 2 http://example.com/script.php
Run Code Online (Sandbox Code Playgroud)

但它不是将-d每个请求的参数分开,而是将它们加在一起。

有什么办法可以用 cURL 实现我想要的吗?

如果没有,Linux 系统上是否有其他工具(例如 Wget)可以执行上述操作?

小智 9

从 curl 7.36.0 开始,--nextor-:命令行选项允许分隔 URL 及其相关选项。从curl 手册页

例如,您可以在单个命令行中执行 GET 和 POST 操作:

curl www1.example.com --next -d postthis www2.example.com
Run Code Online (Sandbox Code Playgroud)

您想要的请求可能是:

curl -d "a=1" -o 1 http://example.com/script.php --next -d "a=2" -o 2 http://example.com/script.php
Run Code Online (Sandbox Code Playgroud)