curl --data "param1=value1¶m2=value2" https://example.com/resource.cgi
With fields specified individually:
curl --data "param1=value1" --data "param2=value2" https://example.com/resource.cgi
curl --form "email@example.com" https://example.com/resource.cgi
Multipart with fields and a filename:
curl --form "firstname.lastname@example.org;filename=desired-filename.txt" --form param1=value1 --form param2=value2 https://example.com/resource.cgi
curl --data '' https://example.com/resource.cgi curl -X POST https://example.com/resource.cgi curl --request POST https://example.com/resource.cgi
With libcurl, use the
curl_formadd() function to build your form before submitting it in the usual way. See the libcurl documentation for more information.
For large files, consider adding parameters to show upload progress:
curl --tr-encoding -X POST -v -# -o output -T filename.dat \ http://example.com/resource.cgi
-o output is required, otherwise no progress bar will appear.
For a RESTful HTTP POST containing XML:
curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:text/xml"
or for JSON, use this:
curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:application/json"
This will read the contents of the file named
filename.txt and send it as the post request.
If you want to login to a site, do the following:
curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://localhost/Login curl -L -b headers http://localhost/
The first request saves the session cookie (that is provided upon successful login) in the "headers" file. From now on you can use that cookie to authenticate you to any part of the website that you usually access after logging in with a browser.
If you are lazy, you can get google-chrome to do all the work for you.
- Right-click the form you want to submit and select Inspect. This will open the DevTools panel.
- Select the Network tab in devtools and tick the Preserve log checkbox.
- Submit the form and locate the entry with method POST (right-click on any column header and make sure Method is checked).
- Right click the line with POST, and select Copy > Copy as cURL.
Chrome will copy all the request data in cURL syntax.
--data 'param1=hello¶m2=world' which you can make more readable by using a single
-F per parameter depending on which type of POST request you want to send, which can be either
This will be POST-ed as
application/x-www-form-urlencoded (used for the majority of forms that don't contain file uploads):
curl http://httpbin.org/post \ -H "User-Agent: Mozilla/2.2" \ -d param1=hello \ -d name=dinsdale
multipart/form-data POST use
-F (typically used with forms that contain file uploads, or where order of fields is important, or where multiple fields with the same name are required):
curl http://httpbin.org/post \ -H "User-Agent: Mozilla/2.2" \ -F param1=hello \ -F name=dinsdale \ -F name=piranha
User-Agent header is not normally needed, but I've thrown it in just in case. You can avoid having to set the user agent on every request by creating the
~/.curlrc file which contains e.g.
protected by studiohack♦ May 11 '11 at 16:02
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?