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


1. wget –debug

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

[root@localhost ~]# wget --debug http://192.168.1.101:8080/UFE/service/test
DEBUG output created by Wget 1.12 on linux-gnu.

--2015-03-31 19:01:03--  http://192.168.1.101:8080/UFE/service/test
正在連接 192.168.1.101:8080... 已連接。
Created socket 3.
Releasing 0x000000000087cca0 (new refcount 0).
Deleting unused 0x000000000087cca0.

---request begin---
GET /UFE/service/test HTTP/1.0
User-Agent: Wget/1.12 (linux-gnu)
Accept: */ *
Host: 192.168.1.101:8080
Connection: Keep-Alive

---request end---
已發出 HTTP 請求,正在等待回應...
---response begin---
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE
Access-Control-Max-Age: 3600
Access-Control-Allow-Headers: x-requested-with
Content-Type: text/plain;charset=ISO-8859-1
Content-Length: 14
Date: Tue, 31 Mar 2015 11:13:47 GMT
Connection: keep-alive

---response end---
200 OK
Registered socket 3 for persistent reuse.
長度:14 [text/plain]
正在保存至: “test.1100%[======================================>] 14          --.-K/s   in 0s

2015-03-31 19:01:03 (2.03 MB/s) - 已保存 “test.1” [14/14])

2. wget -save-headers

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

3. wget --spider

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

[root@localhost ~]# wget --spider -nv http://ip/bugfree/index.php
2015-03-31 19:12:42 URL: http://ip/bugfree/index.php/site/login 200 OK

4. curl -v

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

[root@localhost ~]# curl -v http://192.168.1.101:8080/UFE/service/test
* About to connect() to 192.168.1.101 port 8080 (#0)
*   Trying 192.168.1.101... connected
* Connected to 192.168.1.101 (192.168.1.101) port 8080 (#0)
> GET /UFE/service/test HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.14.0.0 zlib/1.2.8 libidn/1.18 libssh2/1.4.2
> Host: 192.168.1.101:8080
> Accept: */ *
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE
< Access-Control-Max-Age: 3600
< Access-Control-Allow-Headers: x-requested-with
< Content-Type: text/plain;charset=ISO-8859-1
< Content-Length: 14
< Date: Tue, 31 Mar 2015 11:28:11 GMT
<
* Connection #0 to host 192.168.1.101 left intact
* Closing connection #0

5. curl -I

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

[root@localhost ~]# curl -I http://192.168.1.101:8080/UFE/service/test
HTTP/1.1 405 Method Not Allowed
Server: Apache-Coyote/1.1
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE
Access-Control-Max-Age: 3600
Access-Control-Allow-Headers: x-requested-with
Allow: GET
Content-Type: text/html;charset=utf-8
Content-Language: en
Content-Length: 1047
Date: Tue, 31 Mar 2015 11:31:42 GMT

6. 獲取url的狀態碼

[root@localhost ~]# curl -o /dev/null -s -w %{http_code} http://192.168.1.101:8080/UFE/service/test
200


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM