Linux系统中curl命令常用参数以及使用方法 – 21运维
通知: .-...

Linux系统中curl命令常用参数以及使用方法

linux 21运维 4959浏览 0评论

linux系统下curl命令是通过url语法在命令行下上传或下载文件的工具软件,它支持http,https,ftp,ftps,telnet等多种协议,常被用来抓取网页和监控Web服务器状态。
1,查看网站内容
curl  url
比如curl www.baidu.com 显示内容比较多,这里不展示,请自行测试。

2,查看网站或网页地址http状态,常用
curl  -I url地址

[root@Master public_html]# curl  -I 21yunwei.com
HTTP/1.1 301 Moved Permanently
Server: nginx/1.2.9
Date: Sun, 08 May 2016 18:56:14 GMT
Content-Type: text/html; charset=UTF-8
Connection: keep-alive
X-Powered-By: PHP/5.3.29
Location: http://www.21yunwei.com/

3. curl使用代理
linux curl使用http代理抓取页面:

curl -x 1.2.3.4:80 http://iframe.ip138.com/ic.asp|iconv -fgb2312
curl -x 1.2.3.4:80 -U aiezu:password http://www.baidu.com
curl --socks4 1.2.3.4:443 http://iframe.ip138.com/ic.asp|iconv -fgb2312
curl --socks5 1.2.3.4:443 http://iframe.ip138.com/ic.asp|iconv -fgb2312

4.curl处理cookies
接收cookies:

curl -c /tmp/cookies http://www.baidu.com #cookies保存到/tmp/cookies文件
curl -b "key1=val1;key2=val2;" http://www.baidu.com #发送cookies文本
curl -b /tmp/cookies http://www.baidu.com #从文件中读取cookies
5. curl发送数据:

linux curl get方式提交数据:

curl -G -d "name=value&name2=value2" http://www.baidu.com

linux curl post方式提交数据:

curl -d "name=value&name2=value2" http://www.baidu.com #post数据
curl -d a=b&c=d&txt@/tmp/txt http://www.baidu.com  #post文件

6. http header处理:

设置http请求头信息:

curl -A "Mozilla/5.0 Firefox/21.0" http://www.baidu.com #设置http请求头User-Agent
curl -e "http://pachong.org/" http://www.baidu.com #设置http请求头Referer
curl -H "Connection:keep-alive \n User-Agent: Mozilla/5.0" http://www.aiezu.com
  设置http响应头处理:
curl -I http://www.21yunwei.com #仅仅返回header
curl -D /tmp/header http://www.21yunwei.com #将http header保存到/tmp/header文件

7. curl认证:

curl -u 21yunwei:password http://www.21yunwei.com #用户名密码认证
curl -E mycert.pem https://www.baidu.com #采用证书认证
curl -# http://www.baidu.com #以“#”号输出进度条
curl -o /tmp/hehe  http://www.baidu.com #保存http响应到/tmp/hehe  

转载请注明:21运维 » Linux系统中curl命令常用参数以及使用方法

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址