What is the cURL command-line syntax to do a POST request?

How can I make a POST request with the cURL command-line tool?


With fields:

curl --data "param1=value1&param2=value2" https://example.com/resource.cgi


curl --form "[email protected]" https://example.com/resource.cgi

Multipart with fields and a filename:

curl --form "[email protected];filename=desired-filename.txt" --form param1=value1 --form param2=value2 https://example.com/resource.cgi

Without data:

curl --data '' https://example.com/resource.cgi

curl -X POST https://example.com/resource.cgi

curl --request POST https://example.com/resource.cgi

For more information see the cURL manual. The cURL tutorial on emulating a web browser is helpful.

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 \

The -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.

Data from stdin: use -d @-. Example:

echo '{"text": "Hello **world**!"}' | curl -d @- https://api.github.com/markdown


<p>Hello <strong>world</strong>!</p>

curl -d "name=Rafael%20Sagula&phone=3320780" http://www.where.com/guest.cgi

is the example found in the Curl Example Manual.

Use %26 for the ampersands though if the above doesn't work:

curl -d "name=Rafael%20Sagula%26phone=3320780" http://www.where.com/guest.cgi

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.

curl -v --data-ascii var=value http://example.com

and there are many more options, check curl --help for more information.

Category: http Time: 2008-09-17 Views: 3
Tags: http curl

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.205 (s). 12 q(s)