Getting curl to output HTTP status code?
A more specific way to print out just the HTTP status code is something along the lines of:
curl -s -o /dev/null -w "%{http_code}" http://www.example.org/
A lot easier to work with in scripts, as it doesn't require any parsing :-)
The parameter -I
might be added to improve response load performance. This will change the call to a HEAD
call which will fetch response overhead only, without the body.
Note: %{http_code}
returns on first line of HTTP payload
i.e.:
curl -s -o /dev/null -I -w "%{http_code}" http://www.example.org/
This should work for you if the web server is able to respond to HEAD requests (this will not perform a GET
):
curl -I http://www.example.org
As an addition, to let cURL follow redirects (3xx statuses) add -L.
You can print the status code, in addition to all the headers by doing the following:
curl -i http://example.org
The good thing about -i
is that it works with -X POST
as well.