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!
To send the Content-Type header using Curl, you need to use the -H command-line option. For example, you can use the -H "Content-Type: application/json" command-line parameter for JSON data. Data is passed to Curl using the -d command-line option.
The syntax for the curl command is as follows: curl [options] [URL...] In its simplest form, when invoked without any option, curl displays the specified resource to the standard output. The command will print the source code of the example.com homepage in your terminal window.
To manually pass the Content-Length header, you need to add the Content-Length: [length] and Content-Type: [mime type] headers to your request, which describe the size and type of data in the body of the POST request.
To make a Curl request with Credentials, you need to use the --user "username:password" command line parameter and pass the username and password to Curl. The username and password are separated by colons.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With