標籤:date type trace command chosen ssh tac black cto
wget / curl 是兩個比較方便的測試http功能的命令列工具,大多數情況下,測試http功能主要是查看請求響應 頭資訊 ,而給這兩個工具加上適當的命令列參數即可輕易做到,其實查man手冊就能找到對應的參數選項,不過這裡仍然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 have chosen to
compile Wget without debug support, in which case -d will not work. Please note
that compiling with debug support is always safe—Wget compiled with the debug
support will not print any debug info unless requested with -d.
執行個體(可以看到,wget連結請求預設採用的是HTTP/1.0協議):
[[email protected] ~]# wget 127.0.0.1 --debugDEBUG output created by Wget 1.12 on linux-gnu.--2012-05-26 12:32:08-- http://127.0.0.1/Connecting to 127.0.0.1:80... connected.Created socket 3.Releasing 0x09cdfb18 (new refcount 0).Deleting unused 0x09cdfb18.---request 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.1 200 OKServer: nginx/1.2.0Date: Sat, 26 May 2012 04:32:08 GMTContent-Type: text/htmlContent-Length: 186Last-Modified: Fri, 25 May 2012 02:41:59 GMTConnection: keep-aliveAccept-Ranges: bytes---response end---200 OKRegistered socket 3 for persistent reuse.Length: 186 1Saving to: “index.html.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] ~]#
如果wget不帶--debug選項,則可以使用-S、--save-headers選項,不過此時只能查看回應標頭部資訊:
-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 an empty line as the separator.
執行個體:
[[email protected] ~]# wget -S 127.0.0.1--2012-05-26 12:38:32-- http://127.0.0.1/Connecting to 127.0.0.1:80... connected.HTTP request sent, awaiting response... HTTP/1.1 200 OK Server: nginx/1.2.0 Date: Sat, 26 May 2012 04:38:32 GMT Content-Type: text/html Content-Length: 186 Last-Modified: Fri, 25 May 2012 02:41:59 GMT Connection: keep-alive Accept-Ranges: bytesLength: 186 1Saving to: “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] ~]#
利用curl的-v查看請求回應標頭部資訊:
-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 that is hidden in normal cases, and a line starting with ’*’
means additional info provided by curl.
Note that if you only want HTTP headers in the output, -i/--include might be 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.
執行個體(可以看到,wget連結請求預設採用的是HTTP/1.1協議):
[[email protected] aa]# curl -v 127.0.0.1* About to connect() to 127.0.0.1 port 80 (#0)* Trying 127.0.0.1… connected* Connected to 127.0.0.1 (127.0.0.1) port 80 (#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.1 200 OK< Server: nginx/1.2.0< Date: Sat, 26 May 2012 04:45:12 GMT< Content-Type: text/html< Content-Length: 186< Last-Modified: Fri, 25 May 2012 02:41:59 GMT< Connection: keep-alive< Accept-Ranges: bytes<<html><head><title>Welcome to nginx!</title></head><body bgcolor="white" text="black"><center><h1>Welcome to nginx!</h1></center><center><h1>root:web</h1></center></body></html>* Connection #0 to host 127.0.0.1 left intact* Closing connection #0[[email protected] aa]#
利用curl的-I選項僅查看回應標頭部資訊:
-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.
執行個體:
[[email protected] aa]# curl -I 127.0.0.1HTTP/1.1 200 OKServer: nginx/1.2.0Date: Sat, 26 May 2012 04:43:12 GMTContent-Type: text/htmlContent-Length: 186Last-Modified: Fri, 25 May 2012 02:41:59 GMTConnection: keep-aliveAccept-Ranges: bytes[[email protected] aa]#
wget/curl查看請求回應標頭資訊