curl 的典型用法
访问量: 2150
1. 最简单的用法 (GET 80端口):
$ curl www.site.com
1.2 如果希望待上参数,记得用引号把URL 括起来:
$ curl 'www.somesite.com?param1=foo¶m2=bar'
2. 使用 POST 请求:
$ curl www.site.com -X POST -d "say=hi"
使用 header, 并且打印出全程所耗费时间:
$ curl https://site-portal/api/request_token --header "Apikey:35e078e2" --data "username=my_name&password=1234&format=json" -XPOST -w "\n total time: %{time_total} seconds\n"
{"status":"SUCCESS","value":"0564e627"}
total time: 0.030 seconds
注意 其中的 -w 输出,还是比较特别的,必须要放在字符串里,要是直接 -w time_total 则没有内容显示。
3. 使用JSON :
curl http://10.103.xx.yy/push-api/json --request POST --header "Content-Type: application/json" --data '{ "serial":"0.08777515703408345", "test":false, "query":{ "pid":[ ], "version":[ ], "uid":[], "platform":[ 1 ], "app":[ 1 ], "grade":[ 1 ] }, "msg":{ "ios":{ "alert":"test push by Siwei" } } }'