4 ms·
> If you only care about headers use the -I flag and the response body will be hidden That is actually wrong. The -I flag set the request method to HEAD. So in
by k33l0r 14y ago
> If you only care about headers use the -I flag and the response body will be hidden
That is actually wrong. The -I flag set the request method to HEAD. So in some cases it will return different headers than a normal get request (and some servers don't implement HEAD responses at all).
- markild 14y agoVery true, but let's not forget that [0] > The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. and that > The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. [0]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
- eli 14y agoYes, it should work the same. But it's not the same.
- KrisJordan 14y agoAh, great catch. Added a note about having to specify the method explicitly / that -I uses HEAD implicitly. Thanks!
- bonobo 14y agoA better way to view only the header of a response is using the flags -o to redirect the body and -D to redirect the header of the response. When I want to print only the header to stdout I do curl -o/dev/null -D- http://www.example.com -I does not work with methods other than GET. This does the job.
- KrisJordan 14y agoSo you can use -I with another method, but as soon as you add a body curl refuses. Went ahead and just took that scenario out of the post -- but your redirection snippet is great.
- brown9-2 14y agoWhy not just use -i?
- bonobo 14y ago-i mixes the header and the body of the response into one stream. If you want only the header it won't help.
- brown9-2 14y agoNote that -I and -i are different: -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... -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 an FTP or FILE file, curl displays the file size and last modification time only.
- eik3_de 14y agoThat's why I have this in the shell config and use it daily: alias h='curl -sIX GET -w "Total time: %{time_total} s\n"' It issues a GET request, only prints the response headers and displays the time it took.