CURL:如何运行单个curl命令100次?

10
我有以下curl命令: curl -i -H“Content-Type:text / plain”-X POST -d @hundredencoded http:// / aaa / bbb / message 为了进行负载测试,我需要使用CURL运行此命令100次,我该怎么做?
谢谢您的帮助。

1
可能使用一个 shell 脚本。使用哪个平台? - Fred Foo
你可以在Shell脚本中尝试使用for循环来执行上述代码。 - Akshay Joy
2个回答

16
你可以通过使用以下脚本来实现它:


#!/bin/bash

for i in $(eval echo {1..$1})
do 
  curl -i -H 'Content-Type: text/plain' -X POST -d @hundredencoded http:///aaa/bbb/message &  
done

谢谢回复。但是当我运行run.sh时出现了这个错误。gnome-terminal:找不到命令。 - user2377310
@user2377310,你在用什么平台?不是Linux吗? - qwr
我正在MAC终端窗口上运行这个程序。 - user2377310
1
很难理解为什么每个curl都要弹出一个终端,或者根本不需要。只需在后台运行:curl [...] &,如果您不想有大量作业,请在&后添加“disown”。 - jthill
这个成功了!谢谢!:) #!/bin/bashfor i in $(eval echo {1..$1}) do curl -i -H "Content-Type: text/plain" -X POST -d @hundredencoded http:///aaa/bbb/message ;done - user2377310
@user2377310 在 jthill 建议后在末尾加上 & 使其后台运行。我也编辑了那个脚本。 - qwr

10

虽然问题指定使用curl完成此任务,但我强烈建议使用ab。

ab(Apache Benchmark)是专门针对这种情况构建的工具。它允许您多次调用特定请求并定义并发性。 http://httpd.apache.org/docs/2.0/programs/ab.html

你的测试将是:

ab -p post.txt -H 'Content-Type: text/plain' -n 100 -c 1 http://aaa/bbb/message

或者,更简洁地说:
ab -p post.txt -T text/plain -n 100 -c 1 http://aaa/bbb/message

文件post.txt保存了POST数据。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接