天天看點

curl wget指令常用

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 &lt;format&gt; 。 variables are specified as %{variable_name}

-o -o/--output &lt;file&gt;

-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

繼續閱讀