Frequently Used GET and POST Commands in curl

Several frequently used GET and POST commands in curl are listed here.

GET commands:

curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET

POST commands

POST data
curl --data "param1=value1&param2=value2"

SOAP request (POST)
curl -H "Content-Type: application/xml" --data ""

POST data from a file
curl -H "Content-Type: application/xml" --data "@req.xml"

File upload
curl --form "fileupload=@filename.txt" http://hostname/resource

curl -X POST -d @filename

Logging into a site (auth)
curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://myhost/login

curl -L -b headers http://myhost/

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponEmail this to someoneShare on TumblrDigg this

One thought on “Frequently Used GET and POST Commands in curl

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">