Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 213
David Lobron Avatar asked Jun 30 '15 16:06

David Lobron


People also ask

How do I specify Content-Type in curl command?

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.

How do I use curl command in terminal?

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.

How do you pass content length in curl?

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.

How do I add credentials to curl command?

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.


1 Answers

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"
like image 162
Julien Grégoire Avatar answered Sep 27 '22 20:09

Julien Grégoire