43

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?

random
  • 450
  • 1
  • 9
  • 16
Damiano
  • 431
  • 1
  • 4
  • 3

6 Answers6

52

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

curl -I http://www.example.com/test.php

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.

Lucas
  • 105
  • 4
Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
11

Use wget for instance

wget -O - -o /dev/null --save-headers www.example.com/test.php
Dmytro Leonenko
  • 456
  • 1
  • 7
  • 24
8

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

Lekensteyn
  • 6,241
  • 6
  • 39
  • 55
6

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
MrD
  • 235
  • 5
  • 11
5

You can see them with curl.

yojimbo87
  • 672
  • 5
  • 12
  • 22
3

Use curl --include to include the response-headers in the top of the response-body.

or curl --verbose to see it all including SSL certificate exchanging the handshake (plus other debug information)

if the request itself and neither the response-body are not of you concern, just use curl --head

for example curl --head --no-check-certificate --url "https://example.com".

You can download gnu curl already pre-compiled for the most platforms. curl is quite the useful too, especially if you would like to pipe or redirect the result inside a script.
*for example: https://superuser.com/a/1007898/429721