Skip to content

Instantly share code, notes, and snippets.

View ehausig's full-sized avatar

Eric Hausig ehausig

View GitHub Profile
@ehausig
ehausig / curl-get-status-code-and-response-body.sh
Created November 12, 2021 15:06 — forked from maxclaus/curl-get-status-code-and-response-body.sh
Curl - Get status code and response body
URL="http://stackoverflow.com/"
# store the whole response with the status at the and
HTTP_RESPONSE=$(curl --silent --write-out "HTTPSTATUS:%{http_code}" -X POST $URL)
# extract the body
HTTP_BODY=$(echo $HTTP_RESPONSE | sed -e 's/HTTPSTATUS\:.*//g')
# extract the status
HTTP_STATUS=$(echo $HTTP_RESPONSE | tr -d '\n' | sed -e 's/.*HTTPSTATUS://')