Can I set Content-Type via curl on command-line without adding "boundary=------"?
If you want to send application/xml
, you should use --data
instead of --form
which sends multipart/form-data
. An in your case, it should be the content of the file, not the file itself that you want to send. Like this:
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"
David Lobron
I'm a software engineer in the field of autonomous vehicles, working mostly in C++.
Updated on July 02, 2020Comments
-
David Lobron almost 4 years
I am sending a command-line curl command to a webserver. The webserver only accepts content of type application/xml or application/json. My curl command (slightly edited) is:
curl -k --cert certfile --form "[email protected]" --cacert cacert.pem https://IP:PORT/v1/all/3131 --header "allowed-domains: foo.net" -H "Content-Type:application/xml"
I'm finding that the server rejects this with the following:
POST load request has invalid type application/xml; boundary=----------------------------dc1435dd0d36
The problem is that the server doesn't recognize
"boundary=----------------------------dc1435dd0d36"
Is there a way to tell curl not to include that? Or is this a bug in the server?
I found a related question on SO about this, but it only addressed programs that can set curl options via curl_setopt. Is there a way to do these things on the command line? That earlier question was:
PHP cURL Content-Length and Content-Type wrong
Thanks in advance for any help!
-
David Lobron almost 9 yearsThank you- that worked! I didn't realize that --form would send it as multipart/form-data even if I set the Content-Type explicitly, but it makes sense.
-
eglasius about 3 yearsAlso worked for me. I was trying something like option c of: stackoverflow.com/a/33360009/66372.