Last active
January 9, 2020 18:04
-
-
Save jkbrzt/ad06f159c5afbe278b5fcfa8bf3b5313 to your computer and use it in GitHub Desktop.
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
http --headers \ # Print out the response headers (they would otherwise be supressed for piped ouput) | |
--download \ # Enable download mode | |
--output=./body \ # Save response body to this file | |
httpbin.org/get 2>&1 \ # Merge STDERR into STDOUT (with --download, console output otherwise goes to STDERR) | |
| grep HTTP/ \ # Find the Status-Line | |
| cut -d ' ' -f 2 # Get the status code |
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
STATUS=$(http -hdo ./body httpbin.org/get 2>&1 | grep HTTP/ | cut -d ' ' -f 2) | |
BODY=$(cat ./body) | |
rm ./body | |
echo $STATUS | |
# 200 | |
echo $BODY | |
# { "args": {}, "headers": { "Accept": "*/*", "Accept-Encoding": "identity", "Host": "httpbin.org", "User-Agent": "HTTPie/1.0.0-dev" }, "origin": "84.242.118.58", "url": "http://httpbin.org/get" } | |
--headers Print out the response headers (they would otherwise be supressed for piped ouput)
Thank you! Spent a few minutes trying to figure out wtf is going on.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you