I use curl to get http headers to find http status code and also return response. I get the http headers with the command
curl -I http://localhost
To get the response, I use the command
curl http://localhost
As soon as use the -I flag, I get only the headers and the response is no longer there. Is there a way to get both the http response and the headers/http status code in in one command?
I use this command to print the status code without any other output. Additionally, it will only perform a HEAD request and follow the redirection (respectively
-I
and-L
).This makes it very easy to check the status code in a health script:
The
-i
option is the one that you want:Alternatively you can use the verbose option:
I have used this :
To get the HTTP status
To get the response body I've used this