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工具