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
Windows user running curl binaries should use double-quotes instead of single quotes to get multiple query parameters command working.
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 .
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.
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.
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.
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