linux curl是通過url語法在命令行下上傳或下載文件的工具軟件,它支持http,https,ftp,ftps,telnet等多種協議,常被用來抓取網頁和監控Web服務器狀態。
一、Linux curl用法舉例:
1. linux curl抓取網頁:
抓取百度:
www.baidu.com
2.linux curl下載網頁:
curl -o www.baidu.com
3.linux curl 模擬請求
curl -d 'user=sea24&password=123456' www.baidu.com {注:如果參數出現雙引號則外邊用單引號 。 后邊網址不需要加引號}
4.linux curl處理cookies
curl -c /tmp/cookies http://www.baidu.com #cookies保存到/tmp/cookies文件
發送cookies:
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 發請求
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提交