socke5 使用curl 测试_curl/wget 测试http请求的响应头信息

1. wget –debug

wget可以使用debug信息来查看信息头,如下:

[root@node01 ~]# 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]

[root@node01 ~]#

2. wget -save-headers

以使用-S、–save-headers选项,不过此时只能查看响应头部信息,注意,debug和save-headers都会输出到文件。

3. wget --spider

判断一个文件或者页面是否存在,可以使用一下命令:

[root@node01 ~]# 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.

[root@node01 ~]#

4. curl -v

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

[root@node01 ~]# 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

[root@node01 ~]#

5. curl -I

利用curl的-I(大写i)--head 选项仅查看响应头部信息:

[root@node01 ~]# 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

[root@node01 ~]#

6. 获取url的状态码

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

200

[root@node01 ~]#

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值