Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there a shell command to see the headers of a HTTP request?

For example, I would like to know what the headers retrieved from www.example.com/test.php are

How can I do this?

share|improve this question
add comment

5 Answers

In order to retrieve only the header, give this a try:

curl -I example.com

From the man page:

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

share|improve this answer
    
Also, -D <file> will save the headers to a file. –  coredump Mar 20 '11 at 16:02
add comment

Use wget for instance

wget -O - -o /dev/null --save-headers www.example.com/test.php
share|improve this answer
    
yes, but i don't want to save the page on my pc.....i only want to see the headers –  Damiano Mar 20 '11 at 10:22
2  
You won't save it with this command –  Dmytro Leonenko Mar 20 '11 at 11:01
    
Yup, you're just filling /dev/null :p -O - writes the headers to the stdout ("the console") –  Lekensteyn Mar 20 '11 at 16:00
add comment

You can do that with curl:

curl -i 'http://example.com/'

Result:

HTTP/1.0 302 Found
Location: http://www.iana.org/domains/example/
Server: BigIP
Connection: Keep-Alive
Content-Length: 0

(for some reason, IANA decided to redirect example.com, result: no body)

curls manual page about the -i option:

-i/--include

(HTTP) Include the HTTP-header in the output. The HTTP-header includes things like server-name, date of the document, HTTP-version and more...

share|improve this answer
add comment

You can see them with curl.

share|improve this answer
add comment

Or you can use HEAD http://www.example.com. The result is very similar to that produced by curl -i 'http://example.com/' although it seems to return more headers.

200 OK
Connection: close
Date: Sun, 20 Mar 2011 19:08:58 GMT
Server: Apache/2.2.3 (CentOS)
Content-Length: 2945
Content-Type: text/html; charset=UTF-8
Last-Modified: Wed, 09 Feb 2011 17:13:15 GMT
Client-Date: Sun, 20 Mar 2011 19:09:08 GMT
Client-Peer: 192.0.32.8:80
Client-Response-Num: 1
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.