Reputation: 12362
I read https://superuser.com/questions/272265/getting-curl-to-output-http-status-code . It mentioned that
curl -i
will print the HTTP response code. Is it possible to have curl print just the HTTP response code? Is there a generic way to get the HTTP status code for any type of request like GET/POST/etc?
I am using curl 7.54.0 on Mac OS High Sierra.
Upvotes: 12
Views: 17973
Reputation: 663
Another solution:
curl -sI http://example.org | head -n 1 | cut -d ' ' -f 2
in this way you are:
head -n 1
), which must contain the response HTTP version, the response code and the response message (in this order), each one separated by a whitespace (as defined in the HTTP standard);cut -d ' ' -f 2
), which is the status codeUpvotes: 0
Reputation: 12362
This worked for me:
$ curl -s -w "%{http_code}\n" http://google.com/ -o /dev/null
Upvotes: 22
Reputation: 3486
curl -s -I http://example.org | grep HTTP/ | awk {'print $2'}
output: 200
Upvotes: 2