How to display request headers with command line curl
curl's -v
or --verbose
option shows the HTTP request headers, among other things. Here is some sample output:
$ curl -v http://google.com/* About to connect() to google.com port 80 (#0)* Trying 66.102.7.104... connected* Connected to google.com (66.102.7.104) port 80 (#0)> GET / HTTP/1.1> User-Agent: curl/7.16.4 (i386-apple-darwin9.0) libcurl/7.16.4 OpenSSL/0.9.7l zlib/1.2.3> Host: google.com> Accept: */*> < HTTP/1.1 301 Moved Permanently< Location: http://www.google.com/< Content-Type: text/html; charset=UTF-8< Date: Thu, 15 Jul 2010 06:06:52 GMT< Expires: Sat, 14 Aug 2010 06:06:52 GMT< Cache-Control: public, max-age=2592000< Server: gws< Content-Length: 219< X-XSS-Protection: 1; mode=block< <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"><TITLE>301 Moved</TITLE></HEAD><BODY><H1>301 Moved</H1>The document has moved<A HREF="http://www.google.com/">here</A>.</BODY></HTML>* Connection #0 to host google.com left intact* Closing connection #0
A popular answer for displaying response headers, but OP asked about request headers.
curl -s -D - -o /dev/null http://example.com
-s
: Avoid showing progress bar-D -
: Dump headers to a file, but-
sends it to stdout-o /dev/null
: Ignore response body
This is better than -I
as it doesn't send a HEAD
request, which can produce different results.
It's better than -v
because you don't need so many hacks to un-verbose it.
I believe the command line switch you are looking for to pass to curl is -I
.
Example usage:
$ curl -I http://heatmiser.counterhack.com/zone-5-15614E3A-CEA7-4A28-A85A-D688CC418287 HTTP/1.1 301 Moved PermanentlyDate: Sat, 29 Dec 2012 15:22:05 GMTServer: ApacheLocation: http://heatmiser.counterhack.com/zone-5-15614E3A-CEA7-4A28-A85A-D688CC418287/Content-Type: text/html; charset=iso-8859-1
Additionally, if you encounter a response HTTP status code of 301, you might like to also pass a -L
argument switch to tell curl
to follow URL redirects, and, in this case, print the headers of all pages (including the URL redirects), illustrated below:
$ curl -I -L http://heatmiser.counterhack.com/zone-5-15614E3A-CEA7-4A28-A85A-D688CC418287HTTP/1.1 301 Moved PermanentlyDate: Sat, 29 Dec 2012 15:22:13 GMTServer: ApacheLocation: http://heatmiser.counterhack.com/zone-5-15614E3A-CEA7-4A28-A85A-D688CC418287/Content-Type: text/html; charset=iso-8859-1HTTP/1.1 302 FoundDate: Sat, 29 Dec 2012 15:22:13 GMTServer: ApacheSet-Cookie: UID=b8c37e33defde51cf91e1e03e51657daLocation: noaccess.phpContent-Type: text/htmlHTTP/1.1 200 OKDate: Sat, 29 Dec 2012 15:22:13 GMTServer: ApacheContent-Type: text/html