Created
June 14, 2018 17:55
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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