Curl to return http status code along with the response

后端 未结 12 1170
我在风中等你
我在风中等你 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:46

    I have used this :

        request_cmd="$(curl -i -o - --silent -X GET --header 'Accept: application/json' --header 'Authorization: _your_auth_code==' 'https://example.com')"
    

    To get the HTTP status

        http_status=$(echo "$request_cmd" | grep HTTP |  awk '{print $2}')
        echo $http_status
    

    To get the response body I've used this

        output_response=$(echo "$request_cmd" | grep body)
        echo $output_response
    

提交回复
热议问题