Last active
October 25, 2021 21:58
-
-
Save zmarffy/7eebf20535ce9b642ad5cdfb4ecb20b4 to your computer and use it in GitHub Desktop.
Get an HTTP response as well as the HTTP status code when using `curl`
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
out=$(curl "http://httpbin.org/get?key=value" -w "%{http_code}\\n" -sS) | |
sc=$(echo "$out" | tail -n -1) | |
json=$(echo "$out" | sed \$d) | |
echo -e "STATUS CODE:\n$sc\n\nJSON:\n$json" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment