Tuesday, May 19, 2015

CURL Commands

Here are some valuable curl commands.

GET JSON Request
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET http://hostname/resource

GET XML Request
curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET http://hostname/resource

POST data
curl --data "param1=value1&param2=value2" http://hostname/resource

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

RESTful HTTP Post
curl -X POST -d @filename http://hostname/resource

For logging into a site (auth)
curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://localhost/Login
curl -L -b headers http://localhost/

Reference Site :-

http://stackoverflow.com/questions/14978411/http-post-and-get-using-curl-in-linux
http://www.w3schools.com/json/json_syntax.asp

No comments:

Post a Comment