使用Apache Bench测试POST请求中的图像文件内容

5

我有一个web服务,可以通过http POST接受图像文件,我使用curl发送它们,例如:

curl -X POST -F "image=@ta1.jpeg" -F "image=@ta2.jpeg" http://domain.tld/upload

我正在尝试使用Apache Bench (ab)测试并发请求。我发现ab有一个选项-p可以发布数据,但我认为这需要JSON内容...... 我试图使用postman回声服务将我的图像编码为JSON:

curl -X POST -F "image=@ta1.jpeg" -F "image=@ta2.jpeg" http://www.postman-echo.com/post

将输出保存到文件中,并使用ab-p选项发送,但会产生服务器错误。

有没有关于如何使用Apache Bench测试POST图像的提示?


曾经为同样的问题苦恼,现在找到了答案:https://stackoverflow.com/questions/12584998/apache-benchmark-multipart-form-data - Gennady Kandaurov
2个回答

0
  • 创建一个帖子文件。

例如,创建名为images.txt的文件。确保换行符为CRLF。

--1234567890
Content-Disposition: form-data; name="file"; filename="text1.jpeg"
Content-Type: image/jpeg

[base64 encoded image]
--1234567890
Content-Disposition: form-data; name="file"; filename="text2.png"
Content-Type: image/png

[base64 encoded image]
--1234567890--
  • 脚本

ab -c 1 -n 1 -v 4 -H "Accept-Encoding: gzip, deflate" -T "multipart/form-data; boundary=1234567890" -p "images.txt" "http://url"


0
你尝试设置内容类型了吗?
ab -n 1 -p post -T application/x-www-form-urlencoded -p ta1.jpeg http://domain.tld/upload

当您尝试发布JSON文件时,您需要设置JSON内容类型:

ab -n 1 -p post -T application/json -p ta1.json http://domain.tld/upload

对于两者,我都收到了错误信息“无法将POST与其他方法混合使用”。 - user1981275

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