curl
有時HTTP服務接口寫完,需要驗證下接口功能,這個使用用curl最合適了
curl 全稱 command line url viewer
curl www.taobao.com
curl www.baidu.com # 站點內容
curl -o baidu.html www.baidu.com # 文件保存
curl -L www.taobao.com # 存在跳轉時可以用L參數
curl -i www.sina.com # 顯示頭信息 + 內容
curl -I www.taobao.com # 只顯示頭
curl -v www.taobao.com # 顯示通信過程
curl --trace output.text www.taobao.com # 顯示二進制細節
curl --trace-ascii output.text www.taobao.com # 顯示ascii細節
form 提交
-X 這個參數可以配置HTTP的方法
curl -X POST 127.0.0.1:7001/api/material/update
curl -X POST --data "name=kk&name2=gg" 127.0.0.1:7001/api/material/create # 帶參數的post提交
其他
curl --referer http://www.example.com http://www.example.com # referer
curl —user-agent “userAgent” www.taobao.com
curl --header "Content-Type:application/json" http://example.com # 添加頭
curl -c cookie_output http://example.com # 保存cookie
curl -b cookies_input http://example.com # 使用cookie file 發請求