1 获取返回码:(only)
<code>[root@master zabbix_agentd.conf.d]</code><code># curl -s --connect-timeout 20 -w "%{http_code}" -o /dev/null www.baidu.com</code>
<code>200[root@master zabbix_agentd.conf.d]</code><code>#</code>
参数详解
curl
-s -s/--silent
Silent or quiet mode. Don't show progress meter or error messages. Makes Curl mute.
-I
-w -w/--write-out <format> 。 variables are specified as %{variable_name}
-o -o/--output <file>
-x 使用代理
2 -I 返回头部信息 (HTTP/FTP/FILE) Fetch the HTTP-header only! HTTP-servers feature the command HEAD 是一个head请求
<code>curl -I </code>
<code>http:</code><code>//www</code><code>.baidu.com</code>
<a href="http://www.baidu.com/" target="_blank"></a>
3 -i 返回头部信心+返回的信息(HTTP) Include the HTTP-header in the output
4 -s 的效果
查看有没有-s的效果: 你可以看到那些curl的进度输出
<code>[root@master scripts]</code><code># curl -s -I 192.168.100.13:80 --connect-timeout 2 | sed -n '1p' </code>
<code>HTTP</code><code>/1</code><code>.1 200 OK</code>
<code>[root@master scripts]</code><code># curl -I 192.168.100.13:80 --connect-timeout 2 | sed -n '1p' </code>
<code> </code><code>% Total % Received % Xferd Average Speed Time Time Time Current</code>
<code> </code><code>Dload Upload Total Spent Left Speed</code>
<code> </code><code>0 612 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0</code>
5 返回请求的整个过程详细过程
6 修改请求的头部信息(伪造 伪装)
(HTTP) Extra header to use when getting a web page
6.1 修改user-agent
方法1: curl --user-agent "[User Agent]" [URL]
方法2: curl -H "user-agent:iphone6" 192.168.100.13
如何查看,自己的user-agent是否生效呢? 可以查看那web日志,或者curl -v -H "user-agent:iphone6" 192.168.100.13 查看传输的详细信息。
6.2 修改host
curl -v -H "Host:web1" 192.168.100.13
6.3 如何置空(remove这个头部 -v详细过程可以查看)
curl -v -H "user-agent:" 192.168.100.13
6.4同时设置两个头部
curl -H "Host:web1" -H "user-agent:iphone6" 192.168.100.13
6.5修改refer
curl -H "referer:www.baidu.com" 192.168.100.13
7 -X 指定请求方法 GET POST DELETE OPTIONS默认是-X GET
curl -X GET
curl -X POST -d "data=xxx" example.com/form.cgi
curl -s -XDELETE "
<a href="http://localhost:9200/%24index/" target="_blank">http://localhost:9200/$index/</a>
如果post 多个数据呢?
-d "key1=values" -d "key2=values"
8 -L 有的网址是自动跳转的。使用`-L`参数,curl就会跳转到新的网址。
(HTTP/HTTPS) If the server reports that the requested page has moved to a
different location (indicated with a Location: header and a 3XX response
code), this option will make curl redo the request on the new place
如果要请求到重定向后的内容就需要使用
9 -x 使用代理进行访问 如使用本地squid代理去访问缓存的图片
<code>curl -x </code><code>"127.0.0.1:3128"</code> <code>-I</code>
########################################## wget 的使用方法
rpm安装包
wget-1.12-5.el6_6.1.x86_64
命令选项:
-e 代理
-O 输出
-P 指定存放的目录prefix
命令如下:
1 通过代理下载图片并报错问test.gif文件名
<code> </code><code>wget -e </code><code>"http_proxy=10.59.74.33:3128 "</code> <code>http:</code><code>//img</code><code>.baidu.com</code><code>/img/iknow/zhengwen/</code><code>%E5%B0%8F%E7%9F%A5.gif?t=142382208044 -O </code><code>test</code><code>.gif</code>
本文转自残剑博客51CTO博客,原文链接http://blog.51cto.com/cuidehua/1765553如需转载请自行联系原作者
cuizhiliang