Curl/wget to test the response header information for an HTTP request

Source: Internet
Author: User
Tags ranges

1. Wget–debug

Wget can use the debug information to view the information header, as follows:

[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 for 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 OK

server:nginx/1.10.2

Date:thu, June 02:15:12 GMT

Content-type:text/html

Content-length:23

Last-modified:thu, June 02:10:40 GMT

Connection:keep-alive

ETag: "592F77A0-17"

Accept-ranges:bytes


---response End---

OK

Registered Socket 3 for persistent reuse.

length:23 [text/html]

Saving to: "INDEX.HTML.1"


100%[========================================================================================================== =========================================>]--.-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

To use the-S, –save-headers option, however only the response header information can be viewed at this time, note that both debug and save-headers are output to the file.

3. wget--spider

To determine whether a file or page exists, you can use the command:

[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 ... OK

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

Remote file exists and could contain further links,

But recursion was disabled-not retrieving.


[Email protected] ~]#


4. Curl-v

You can view the file header information for the URL as follows:

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

* About-to-connect () to 192.168.112.129 Port (#0)

* Trying 192.168.112.129 ... Connected

* Connected to 192.168.112.129 (192.168.112.129) port (#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 OK

< server:nginx/1.10.2

< Date:thu, June 02:10:46 GMT

< content-type:text/html

< content-length:23

< Last-modified:thu, June 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

Use the-I (uppercase I)--head option of Curl to view only the response header information:

[Email protected] ~]# curl-i http://192.168.112.129/index.html

http/1.1 OK

server:nginx/1.10.2

Date:thu, June 02:11:36 GMT

Content-type:text/html

Content-length:23

Last-modified:thu, June 02:10:40 GMT

Connection:keep-alive

ETag: "592F77A0-17"

Accept-ranges:bytes


[Email protected] ~]#


6. Get the status code of the URL

[Email protected] ~]# Curl-o/dev/null-s-W%{http_code} http://192.168.112.129/index.html

200

[Email protected] ~]#



This article from "Flat Light is true" blog, please be sure to keep this source http://ucode.blog.51cto.com/10837891/1931204

Curl/wget to test the response header information for an HTTP request

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.