Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using curl on macos to execute a single http request and then get the status code, headers and body
response="$(curl --silent --show-error -i https://google.com)"
status_code="$(echo "$response" | head -1 | awk '{print $2}')"
headers="$(echo "$response" | sed "/^\s*$(printf '\r')*$/q" | sed '/^[[:space:]]*$/d' | tail -n +2)"
body="$(echo "$response" | sed "1,/^\s*$(printf '\r')*$/d")"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.