Tuesday, July 29, 2014

Printing the HTTP status code in curl

This should be easier, but here it is for reference:

curl -w "status: %{http_code}\n" <URL>

1 comment:

  1. If you don't mind the extra output, you can make a `HEAD` request with the `-I` flag:

    $ curl -I http://www.google.com
    HTTP/1.1 200 OK
    Date: Wed, 30 Jul 2014 00:16:24 GMT
    Expires: -1
    Cache-Control: private, max-age=0
    Content-Type: text/html; charset=ISO-8859-1
    Set-Cookie: PREF=ID=96058df09db9116e:FF=0:TM=1406679384:LM=1406679384:S=GOtsYK2SjRJbWOm9; expires=Fri, 29-Jul-2016 00:16:24 GMT; path=/; domain=.google.com
    Set-Cookie: NID=67=WGFiJdtB0dcBEjbSqkodeaXkwm2aUcWocmXh6zw2fy5oBuk8a_eiS4YucOmXmKGJf2QHj1pjNjkygtWVybpt3sAM5KbOSkKDZrJjUfa2dAm_j_H9T5LTuIsMFpL2Duv-; expires=Thu, 29-Jan-2015 00:16:24 GMT; path=/; domain=.google.com; HttpOnly
    P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
    Server: gws
    X-XSS-Protection: 1; mode=block
    X-Frame-Options: SAMEORIGIN
    Alternate-Protocol: 80:quic
    Transfer-Encoding: chunked