curl 用于Linux指令行中去通路網頁
[root@daixuan ~]# curl www.aminglinux.com curl+網址檢視網站源代碼
[root@daixuan ~]# curl -I www.lishiming.net -I省略掉源代碼
HTTP/1.1 301 Moved Permanently 301表示當通路域名www.lishiming.net會自動跳轉到http://www.apelearn.com/bbs/forum.php
Server: nginx/1.0.15
Date: Sat, 21 Nov 2015 06:43:39 GMT
Content-Type: text/html
Content-Length: 185
Connection: keep-alive
Location: http://www.apelearn.com/bbs/forum.php
狀态碼
200 是正常的
3開頭 重定向,在服務端設定了跳轉
301永久重定向
302 臨時重定向
4開頭 請求錯誤
400 Bad Request 語義有誤,目前請求無法被伺服器了解或者請求參數有誤
401 Unauthorized 目前請求需要使用者驗證
403 Forbidden 伺服器已經了解請求,但是拒絕執行它
404 請求失敗,請求所希望得到的資源未被在伺服器上發現
5、6開頭伺服器錯誤
500 Internal Server Error 伺服器遇到了一個未曾預料的狀況,導緻了它無法完成對請求的處理。一般來說,這個問題都會在伺服器端的源代碼出現錯誤時出現
501 Not Implemented
伺服器不支援目前請求所需要的某個功能。當伺服器無法識别請求的方法,并且無法支援其對任何資源的請求。
502 Bad Gateway
作為網關或者代理工作的伺服器嘗試執行請求時,從上遊伺服器接收到無效的響應。
503 Service Unavailable
由于臨時的伺服器維護或者過載,伺服器目前無法處理請求。
[root@daixuan ~]# ping www.baidu.com
PING www.a.shifen.com (103.235.46.39) 56(84) bytes of data.
64 bytes from 103.235.46.39: icmp_seq=1 ttl=45 time=207 ms
[root@daixuan ~]# vim /etc/hosts 在臨時測試域名www.baidu.com為192.168.101.230的情況下
192.168.101.230 www.baidu.com
PING www.baidu.com (192.168.101.230) 56(84) bytes of data.
64 bytes from www.baidu.com (192.168.101.230): icmp_seq=1 ttl=64 time=3.08 ms
[root@daixuan ~]# curl www.baidu.com
curl: (7) couldn't connect to host
[root@daixuan ~]# curl -x 103.235.46.39:80 www.baidu.com -I -x代理設定,指定IP和端口仍然何以正常通路www.baidu.com,不加-x不能正常通路
HTTP/1.1 200 OK
Date: Sat, 21 Nov 2015 07:01:16 GMT
Server: Apache
P3P: CP=" OTI DSP COR IVA OUR IND COM "
[root@daixuan ~]# curl -Iv www.baidu.com -Iv看出通路過程
* About to connect() to www.baidu.com port 80 (#0)
* Trying 103.235.46.39... connected 解析到IP并連接配接
* Connected to www.baidu.com (103.235.46.39) port 80 (#0) User-Agent是浏覽器的表示,谷歌,百度浏覽器都有自己的辨別
> HEAD / HTTP/1.1
> User-Agent: curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.19.1 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: www.baidu.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sat, 21 Nov 2015 07:23:50 GMT
Date: Sat, 21 Nov 2015 07:23:50 GMT
< Content-Type: text/html; charset=utf-8
Content-Type: text/html; charset=utf-8
< Connection: Keep-Alive
Connection: Keep-Alive
< Vary: Accept-Encoding
Vary: Accept-Encoding
[root@daixuan ~]# cul -u username:password http://www.qqq.com 使用使用者名和密碼來通路網站
[root@daixuan ~]# curl -O +圖檔網址 下載下傳圖檔
Dload Upload Total Spent Left Speed
100 3706 100 3706 0 0 4388 0 --:--:-- --:--:-- --:--:-- 113k
[root@daixuan ~]# curl -o baidu.png +圖檔的位址 指定下載下傳名稱下載下傳圖檔
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3706 100 3706 0 0 8591 0 --:--:-- --:--:-- --:--:-- 80565
[root@daixuan ~]# ls
111 1234.txt 1.t #1.txt.bak 3.txt baidu.png install.log 模闆 桌面
1112 1234.txt.bak 1.tar 1.txt.bak 3.txt.bak bd_logo1_31bdc765.png
curl在請求一個網頁的時候,可以指定user_agent,如何做?
curl -A 'aaa' www.aaa.com