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 http://tecbar.net/demo/param

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://tecbar.net/demo/param

POST commands

POST data
curl --data "param1=value1&param2=value2" http://tecbar.net/demo/param

SOAP request (POST)
curl -H "Content-Type: application/xml" --data "" http://tecbar.net/demo/param

POST data from a file
curl -H "Content-Type: application/xml" --data "@req.xml" http://tecbar.net/demo/param

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

RESTful HTTP POST
curl -X POST -d @filename http://tecbar.net/demo/param

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 to Tosha Cancel 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="">