Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Curl multiple data in one POST command

Can anyone tell me if I can (in the command line) issue a POST command that contains a file and other parameters?

I am trying to do something like:

curl -X POST -F "key=myKey&[email protected]"  http://localhost:8080/myRestService/

I am really new in this domain, so excuse me for my basic question. But it does not seems to work well. Any suggestion? Tank you very much

like image 586
Rami Avatar asked Jun 19 '12 13:06

Rami


People also ask

How do you pass multiple parameters in curl command?

Windows user running curl binaries should use double-quotes instead of single quotes to get multiple query parameters command working.

How do I curl POST request?

Users can send data with the POST request using the -d flag. The following POST request sends a user and a pass field along with their corresponding values. POSTing with curl's -d option will include a default header that looks like: Content-Type: application/x-www-form-urlencoded .

How pass JSON data in curl Post?

To post JSON data using Curl, you need to set the Content-Type of your request to application/json and pass the JSON data with the -d command line parameter. The JSON content type is set using the -H "Content-Type: application/json" command line parameter. JSON data is passed as a string.

How do you pass a body in curl command?

You can pass the body of the POST message to Curl with the -d or --data command-line option. Curl will send data to the server in the same format as the browser when submitting an HTML form. To send binary data in the body of a POST message with Curl, use the --data-binary command-line option.


1 Answers

You should use -d param

check a man page http://curl.haxx.se/docs/manpage.html

If you start the data with the letter @, the rest should be a file name to read the data from, or - if you want curl to read the data from stdin. The contents of the file must already be URL-encoded. Multiple files can also be specified. Posting data from a file named 'foobar' would thus be done with --data @foobar.

Try to specify a full path to your file.

like image 176
lc0 Avatar answered Sep 30 '22 12:09

lc0