我使用cURL在Linux上发布一个XML文件,如下所示:
curl -X POST --header "Content-Type: text/xml" -d @test.xml "https://www.example.com"如何检查cURL命令的状态以确定文件是否已发布?
谢谢你的帮助。
发布于 2014-02-27 10:55:58
可以使用-w %{http_code}获取操作的响应状态。
curl -s -o out.txt -w %{http_code} http://www.example.com/在本例中,-s表示静默模式,而-o out.txt则意味着将响应(通常为html)保存到文件中。
对于上面的命令,当200成功时,您将输出它。
发布于 2014-02-27 00:17:35
我不确定是否收到了,但基本上可以检查curl命令的返回值。最后一个命令的返回值存储在变量$?中。
示例:
curl -X POST --header "Content-Type: text/xml" -d @test.xml "https://www.example.com"
ret=$? # store return value for later usage in the error message
if [ $ret != 0 ] ; then
echo "POST failed with exit code $ret"
fi这个可能的错误代码列表可以在手册页的底部找到。它们对调试非常有帮助。
https://stackoverflow.com/questions/22056419
复制相似问题