Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set content type of part of multipart/mixed request in CURL

Tags:

curl

I want to send json request and several files in one http request. I'm using multipart/mixed request for that

curl -H "Content-Type: multipart/mixed" -F "[email protected]; type=application/json" -F "[email protected]" -F "[email protected]" -X POST hostName

request field has application/json content type and by that indication I define that this part is json request and other parts are files.

My question is how to inline request body in curl request. I try to use

curl -H "Content-Type: multipart/mixed" -F "request={"param1": "value1"}" -F "[email protected]" -F "[email protected]" -X POST hostName

but content type of request will be plain/text

like image 707
Nawa Avatar asked Dec 01 '14 14:12

Nawa


People also ask

How do I specify Content-Type in curl?

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 you send a multipart request in curl?

With curl, you add each separate multipart with one -F (or --form ) flag and you then continue and add one -F for every input field in the form that you want to send. The above small example form has two parts, one named 'person' that is a plain text field and one named 'secret' that is a file.

How do I post form data using curl?

To post a web form with Curl, you need to use the -d command line option and pass the form data as key/value pairs. By default, Curl sends an HTTP POST request and posts the provided form data with the application/x-www-form-urlencoded content type.


1 Answers

You can add content-type information after semicolon:

curl -H "Content-Type: multipart/mixed" -F "request={"param1": "value1"};type=application/json"
like image 143
splatch Avatar answered Oct 20 '22 13:10

splatch