5

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 "fileupload=@test.xml" --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!

Community
  • 1
  • 1
David Lobron
  • 1,039
  • 2
  • 12
  • 21

1 Answers1

12

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"
Julien Grégoire
  • 16,864
  • 4
  • 32
  • 57
  • Thank 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. – David Lobron Jul 02 '15 at 14:22
  • Also worked for me. I was trying something like option c of: https://stackoverflow.com/a/33360009/66372. – eglasius Mar 24 '21 at 21:17