Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Getting curl to output HTTP status code?

I'm using curl at the command line on Linux to issue HTTP requests. The response bodies are printed to standard out, which is fine, but I can't see from the man page how to get curl to print the HTTP status code from the response (404, 403 etc). Is this possible?
by

2 Answers

espadacoder11
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}" example website

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}" example website
sandhya6gczb
You can print the status code, in addition to all the headers by doing the following:

curl -i url

The good thing about -i is that it works with -X POST as well.

Login / Signup to Answer the Question.