Quantcast
Channel: sleeplessbeastie's notes
Viewing all articles
Browse latest Browse all 770

How to display HTTP response code

$
0
0

Use curl utility to verify HTTP response code for given URL.

The simplest way to display HTTP response code is to use quiet mode, discard output and display the numerical response code that was found in the last retrieved transfer after executing GET method.

$ curl --silent --output /dev/null --write-out "%{http_code}\n" http://sleeplessbeastie.eu
301

The above-mentioned solution does not follow redirects, so we need to follow Location: header and a 3XX response code.

$ curl --location --silent --output /dev/null --write-out "%{http_code}\n" http://sleeplessbeastie.eu
200

This solution can be upgraded further to fetch only headers instead of the whole document, but you need to be aware that HEAD method can be blocked on the server side, which is kind of silly as the HEAD method is identical to the default GET except that it does not return message body - only headers.

$ curl --head --location --silent --output /dev/null --write-out "%{http_code}\n" http://sleeplessbeastie.eu
200

Viewing all articles
Browse latest Browse all 770

Trending Articles