Can I have curl print just the response code?

2019-06-06 00:31发布

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.

Thanks for reading.

标签: http curl
2条回答
家丑人穷心不美
2楼-- · 2019-06-06 00:42

This worked for me:

$  curl -s -w "%{http_code}\n" http://google.com/ -o /dev/null
查看更多
仙女界的扛把子
3楼-- · 2019-06-06 00:45
curl -s -I http://example.org | grep HTTP/ | awk {'print $2'}

output: 200

查看更多
登录 后发表回答