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
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.
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.
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.
You can add content-type information after semicolon:
curl -H "Content-Type: multipart/mixed" -F "request={"param1": "value1"};type=application/json"
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