Wget/curl Viewing Request response header information

Source: Internet
Author: User
Tags ranges

Wget/curl is two of the most convenient command-line tools for testing HTTP features, in most cases, the test HTTP function is mainly to look at the request response header information, and the two tools with the appropriate command line parameters can be easily done, in fact, the man manual can find the corresponding parameter options, But this is still mark.

wget--debug
Turn on debug output, meaning various information important to the developers of
Wget if it does not work properly. Your system administrator may has chosen to
Compile Wget without debug support, in which case-d won't work. Please note
That's compiling with debug support are always safe-wget compiled with the debug
Support won't print any debug info unless requested with-d.

Instance (as you can see, the wget link request is by default the http/1.0 protocol):

[[Email protected] ~]# wget 127.0.0.1--debugdebug output created by wget1.12 on Linux-gnu.--2012-05-2612:32:08--/HTTP127.0.0.1/connecting to127.0.0.1:Connected. Created socket3.Releasing0x09cdfb18 (New RefCount0). Deleting Unused0x09cdfb18.---request to begin---get/http/1.0user-agent:wget/1.12 (LINUX-GNU)Accept: */*Host:127.0.0.1Connection:keep-alive---request end---HTTP request sent, awaiting response ...---response begin---http/1.1OKserver:nginx/1.2.0Date:sat,May201204:32:GMTContent-type:text/htmlContent-length:186Last-modified:fri,May201202:41:-GMTConnection:keep-aliveAccept-ranges:bytes---response end---200 okregistered socket 3 for persistent reuse. length: 186 1Saving to: "index.html< Span class= "Hljs-number" >.42 "100%[=================================================== =============>] 186--.-k/s in 0s  2012-05-26  12: 32:08 (4.72 MB/s)-"Index.html.42 "saved [186/186][[email  Protected] ~]#            

If wget does not have the--DEBUG option, you can use the-S 、--save-headers option, but only the response header information is available at this time:
-S
–server-response
Print the headers sent by HTTP servers and responses sent by FTP servers.

–save-headers
Save the headers sent by the HTTP server to the file, preceding the actual contents,
With a empty line as the separator.

Instance:

[Email protected] ~]#Wget-S127.0.0.1--2012-05-2612: 38: 32--http127.0.0.1/ConnectingTo127.0.0.1: 80 ...Connected.HTTPRequestSentAwaitingResponse ...http/1.1200OkServer:nginx/1.2.0Date:Sat26May201204: 38: 32GmtContent-type:text/HtmlContent-length:186Last-modified:Fri,25May201202: 41: 59GmtConnection:Keep-aliveAccept-ranges:bytesLength:1861SavingTo: "Index. html.44 "100%[========================================= =======================>] 186 --.-k/s in 0s 2012-05-26 12:38:32 (4.52 MB/s) -"index.html.44" saved [186/186][[email protected] ~]#         

Use Curl's-V To view request response header information:
-v/–verbose
Makes the fetching more verbose/talkative. Mostly useful for debugging. A Line
Starting with ' > ' means ' header data ' sent by curl, ' < ' means ' header data '
Received by curl (hidden in normal cases, and a line starting with ' * '
means additional info provided by Curl.

Note If you have want HTTP headers in the output,-i/--include might is the
Option you ' re looking for.

If you think this option still doesn ' t give you enough details, consider using
--trace or--trace-ascii instead.

This option overrides previous uses of--trace-ascii or--trace.

Use-s/--silent to make curl quiet.

Instance (as you can see, the wget link request is by default the http/1.1 protocol):

[Email protected] aa]# curl-v127.0.0.1* aboutTo connect ()To127.0.0.1 port80 (#0) * Trying127.0.0.1 connected* ConnectedTo127.0.0.1 (127.0.0.1) port80 (#0) > get/http/1.1> User-agent:curl/7.19.7 (i686-PC-LINUX-GNU) libcurl/7.19.7 nss/3.12.7.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2> HosT:127.0.0.1> ACCEPT: */*>< http/1.1ok< server:nginx/1.2.0< Date:sat,May201204:45:gmt< content-type:text/html< content-length:186< Last-modified:fri,May201202:41:gmt< connection:keep-alive< Accept-ranges:bytes<<title>welcome to nginx!</title> "White "Text=<center> to nginx!center><center>t:web< /h1></center></body>0 to host 127.0. 0.1 left intact* Closing connection #0[[email protected] aa]#                 

Use the-i option of curl to view only the response header information:
-i/--head
(Http/ftp/file) Fetch the Http-header only! Http-servers feature the command HEAD
Which this uses to get nothing but the header of a document. When used on a FTP
or file file, curl displays the file size and last modification time only.

Instance:

[[email protected] AA]# curl-i 127.0.0.1http/1.1 200 okserver:nginx/1.2.0date:sat, 26 may Span class= "Hljs-number" >2012 04: 43: 12 gmtcontent-type:text/html Content-length: 186last-modified:fri, 25 may 2012  02: 41:59 gmtconnection:keep-aliveaccept-ranges:bytes[[email protected] aa]#    

Wget/curl View Request response header information

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.