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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值