免責聲明

Disclaimer (免責聲明)
繼續閱覽代表您接受以上的免責聲明.
To continue reading means you accept the above disclaimer.

2015年4月16日 星期四

curl post, get


//=== http://stackoverflow.com/questions/14978411/http-post-and-get-using-curl-in-linux


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

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


POST for posting data:
curl --data "param1=value1¶m2=value2" http://hostname/resource


POST 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/



//===
GET approach with JSON result
curl -i -H "Accept: application/json" http://someHostName/someEndpoint | grep }| python -mjson.tool


POST approach with JSON result
curl -X POST -H "Accept: Application/json" -H "Content-Type: application/json" http://someHostName/someEndpoint -d '{"id":"IDVALUE","name":"Mike"}' | grep }| python -mjson.tool




//===
man curl:
-H/--header

(HTTP) Extra header to use when getting a web page. You may specify
any number of extra headers. Note that if you should add a custom
header that has the



//===
curl --header "X-MyHeader: 123" www.google.com


沒有留言:

張貼留言