curl 命令简介
cURL 是command URL的缩写,它调用libcurl库,支持多种协议。官方页面
常用命令
参考官方文档,命令忒多了…
以下只讨论最基础的一部分常用命令
尝试一个最常见的网址
curl “http://www.baidu.com”
-o 保存页面
curl -o /tmp/baidu.html “http://www.baidu.com”
-o 指定文件名保存
curl -O “http://www.linux.com/img/001.jpg”
-O使用服务默认文件名保存,支持[001-999].jpg批量下载
-c 保存cookie
curl -c /tmp/cookie.txt http://www.baidu.com
-b 使用cookie访问
curl -b /tmp/cookie.txt http://www.baidu.com
-x 使用proxy服务器访问
curl -x 192.168.100.123:1080 http://www.google.com.hk
-X 强制指定request方法
curl -X GET http://localhost:9200
-L 强制重定向
curl -L http://www.google.com
如访问google时阻止其跳转到google.com.hk
-I 只显示header头文件
curl -I http://www.baidu.com
-w 指定显示信息
curl -w “%{http_code}\n” http://www.example.net
-D 下载头文件
下载头文件到header.txt
curl -D /tmp/header.txt http://www.baidu.com
使用-D下载的header信息多于-c 下载的cookie
-A agent模式
curl -A “Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.0)” http://www.baidu.com
模拟Windows IE8访问了baidu
-u 设置用户名密码,可结合-T 上传、ftp等命令
curl -u username https://api.github.com/user?access_token=XXXXXXXXXX
curl -T UPLOAD.JPG -u USER:PASSWORD ftp://www.linux.com/img/
上传文件
curl -O -u USER:PASSWORD ftp://www.linux.com/img/UPLOAD.JPG
下载文件
其他协议,如使用dict查字典
查询bash单词的含义
curl dict://dict.org/d:bash
列出所有可用词典
curl dict://dict.org/show:db
在foldoc词典中查询bash单词的含义
curl dict://dict.org/d:bash:foldo
-s 静默模式
curl -s http://www.baidu.com
不显示进度和错误
-d 模拟POST提交数据
curl -d “user=USERNAME&password=PASSWORD” http://www.yahoo.com/login.cgi
-F 模拟form提交数据
curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi
-e 指定来源地址
curl -e “www.sina.com” http://mail.sina.com
模拟原地址,突破防盗链
-E 指定证书
curl -E localcert.pem https://remote_server
参考资料
https://curl.haxx.se/
http://blog.csdn.net/weiwangchao_/article/details/23174095
http://www.cnblogs.com/duhuo/p/5695256.html