curl是利用URL語法在命令行方式下工做的開源文件傳輸工具,它支持http,https,ftp,ftps,telnet等多種協議。
經常使用於模擬提交web數據,與網站API交互(POST/GET請求,能夠自定義發送header),也能夠用於下載(PS:專職下載仍是用wget,支持recursive)。html
curl http://www.xxxx.com/show?userId=111
curl -d "username=sunnyxd&password=12345" URL
curl -F filename=@/home/sunnyxd/file.tar.gz -F username=sunnyxd URL
curl URL -b "username=sunnyxd;password=12345"
curl -d "username=sunnyxd&password=12345" -c ./cookie.txt URL 操做結束後把cookie寫入文件cookie.txt
抓取頁面保存到test.html:linux
curl -o test.html URL 或者curl URL > test.html -O 下載特定文件,url須要指定到一個具體的文件 -C - 斷點續傳,- 自動推斷出正確的續傳位置,或者直接指定相應的字節偏移 -f 顯示抓取錯誤信息 -x ip:port 使用代理 -s 不顯示進度信息 -e/--referer 僞造來源地址 --limit-rate 50k 限制下載速度 --max-filesize bytes 指定可下載的最大文件大小
-w 一次完整且成功的操做後輸出指定格式的內容到標準輸出。web
curl -o /dev/null -s -w "%{time_connect}:%{time_starttransfer}:%{time_total}\n" URL 第一個字段,是從命令啓動到連接上用的時間 第二個字段,是開始傳輸數據所用的時間 第三個字段,是完成傳輸所用的時間
curl -o /dev/null -s -w %{http_code} URL
監控接口可用性的一個簡單demo:瀏覽器
#!/bin/bash echo "check result:" cat monitor_url | while read line do status_code=`curl -o /dev/null -s -w %{http_code} $line` if [ $status_code -eq 200 ] then echo ${line}"is ok" else echo ${line}"is fail" fi done
curl -w詳細介紹:http://www.letuknowit.com/post/17.htmlbash
curl URL -A "Mozilla/5.0
經過-I或者--head能夠只打印出HTTP頭部信息:cookie
curl -I URL
用於HTTP或者FTP的認證,能夠指定密碼,也能夠不指定密碼在後續操做中輸入密碼:app
curl -u user:pwd URL curl -u user URL
curl -H "Host:127.0.0.1" -H "accept-language:zh-cn" URL
有的網址是自動跳轉的。使用-L參數,curl就會跳轉到新的網址。curl
curl -L URL
curl --connect-timeout seconds URL
curl -m seconds URL
參數詳細介紹請看這裏:http://man.linuxde.net/curl
參考文章:http://blog.csdn.net/xifeijian/article/details/9367339工具