1. 程式人生 > >curl/wget 測試http請求的響應頭信息

curl/wget 測試http請求的響應頭信息

curl wget檢查http請求包頭信息

1. wget –debug

wget可以使用debug信息來查看信息頭,如下:

[[email protected] ~]# wget --debug http://192.168.112.129/index.html

DEBUG output created by Wget 1.12 on linux-gnu.


--2017-06-01 10:15:12-- http://192.168.112.129/index.html

Connecting to 192.168.112.129:80... connected.

Created socket 3.

Releasing 0x0000000000e92340 (new refcount 0).

Deleting unused 0x0000000000e92340.


---request begin---

GET /index.html HTTP/1.0

User-Agent: Wget/1.12 (linux-gnu)

Accept: */*

Host: 192.168.112.129

Connection: Keep-Alive


---request end---

HTTP request sent, awaiting response...

---response begin---

HTTP/1.1 200 OK

Server: nginx/1.10.2

Date: Thu, 01 Jun 2017 02:15:12 GMT

Content-Type: text/html

Content-Length: 23

Last-Modified: Thu, 01 Jun 2017 02:10:40 GMT

Connection: keep-alive

ETag: "592f77a0-17"

Accept-Ranges: bytes


---response end---

200 OK

Registered socket 3 for persistent reuse.

Length: 23 [text/html]

Saving to: “index.html.1”


100%[===================================================================================================================================================>] 23 --.-K/s in 0s


2017-06-01 10:15:12 (2.82 MB/s) - “index.html.1” saved [23/23]


[[email protected] ~]#

2. wget -save-headers

以使用-S、–save-headers選項,不過此時只能查看響應頭部信息,註意,debug和save-headers都會輸出到文件。

3. wget --spider

判斷一個文件或者頁面是否存在,可以使用一下命令:

[[email protected] ~]# wget --spider nv http://192.168.112.129/index.html

Spider mode enabled. Check if remote file exists.

--2017-06-01 10:09:08-- http://nv/

Resolving nv... failed: Temporary failure in name resolution.

wget: unable to resolve host address “nv”

Spider mode enabled. Check if remote file exists.

--2017-06-01 10:09:18-- http://192.168.112.129/index.html

Connecting to 192.168.112.129:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 3698 (3.6K) [text/html]

Remote file exists and could contain further links,

but recursion is disabled -- not retrieving.


[[email protected] ~]#


4. curl -v

可以查看url的文件頭信息,如下:

[[email protected] ~]# curl -v http://192.168.112.129/index.html

* About to connect() to 192.168.112.129 port 80 (#0)

* Trying 192.168.112.129... connected

* Connected to 192.168.112.129 (192.168.112.129) port 80 (#0)

> GET /index.html HTTP/1.1

> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2

> Host: 192.168.112.129

> Accept: */*

>

< HTTP/1.1 200 OK

< Server: nginx/1.10.2

< Date: Thu, 01 Jun 2017 02:10:46 GMT

< Content-Type: text/html

< Content-Length: 23

< Last-Modified: Thu, 01 Jun 2017 02:10:40 GMT

< Connection: keep-alive

< ETag: "592f77a0-17"

< Accept-Ranges: bytes

<

this is a test website

* Connection #0 to host 192.168.112.129 left intact

* Closing connection #0

[[email protected] ~]#


5. curl -I

利用curl的-I(大寫i)--head 選項僅查看響應頭部信息:

[[email protected] ~]# curl -I http://192.168.112.129/index.html

HTTP/1.1 200 OK

Server: nginx/1.10.2

Date: Thu, 01 Jun 2017 02:11:36 GMT

Content-Type: text/html

Content-Length: 23

Last-Modified: Thu, 01 Jun 2017 02:10:40 GMT

Connection: keep-alive

ETag: "592f77a0-17"

Accept-Ranges: bytes


[[email protected] ~]#


6. 獲取url的狀態碼

[[email protected] ~]# curl -o /dev/null -s -w %{http_code} http://192.168.112.129/index.html

200

[[email protected] ~]#



本文出自 “平平淡淡才是真” 博客,請務必保留此出處http://ucode.blog.51cto.com/10837891/1931204

curl/wget 測試http請求的響應頭信息