Curl to return http status code along with the response

后端 未结 12 1173
我在风中等你
我在风中等你 2020-12-04 08:24

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

12条回答
  •  长情又很酷
    2020-12-04 08:29

    I was able to get a solution by looking at the curl doc which specifies to use - for the output to get the output to stdout.

    curl -o - http://localhost
    

    To get the response with just the http return code, I could just do

    curl -o /dev/null -s -w "%{http_code}\n" http://localhost
    

提交回复
热议问题