我可以在不添加 "boundary=------" 的情况下通过命令行上的 curl 设置 Content-Type 吗?

Can I set Content-Type via curl on command-line without adding "boundary=------"?

我正在向网络服务器发送命令行 curl 命令。网络服务器只接受 application/xml 或 application/json 类型的内容。我的 curl 命令(稍作编辑)是:

curl -k  --cert certfile --form "fileupload=@test.xml" --cacert cacert.pem https://IP:PORT/v1/all/3131 --header "allowed-domains: foo.net" -H "Content-Type:application/xml"

我发现服务器拒绝了以下内容:

POST load request has invalid type application/xml; boundary=----------------------------dc1435dd0d36

问题是服务器无法识别

"boundary=----------------------------dc1435dd0d36"

有没有办法告诉 curl 不要包含它?或者这是服务器中的错误?

我在 SO 上找到了一个关于此的相关问题,但它只解决了可以通过 curl_setopt 设置 curl 选项的程序。有没有办法在命令行上做这些事情?之前的问题是:

PHP cURL Content-Length and Content-Type wrong

在此先感谢您的帮助!

如果你想发送application/xml,你应该使用--data而不是发送multipart/form-data--form。在您的情况下,它应该是文件的内容,而不是您要发送的文件本身。像这样:

curl -k  --cert certfile --data "@test.xml" --cacert cacert.pem https://IP:PORT/v1/all/3131 --header "allowed-domains: foo.net" -H "Content-Type:application/xml"