Skip to content

Instantly share code, notes, and snippets.

@lhazlewood
Created June 14, 2018 17:55
Show Gist options
  • Save lhazlewood/5439d8fd2e6956e4d7085c6fc9d59ad1 to your computer and use it in GitHub Desktop.
Save lhazlewood/5439d8fd2e6956e4d7085c6fc9d59ad1 to your computer and use it in GitHub Desktop.
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