Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jkbrzt/ad06f159c5afbe278b5fcfa8bf3b5313 to your computer and use it in GitHub Desktop.
Save jkbrzt/ad06f159c5afbe278b5fcfa8bf3b5313 to your computer and use it in GitHub Desktop.
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
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" }
@aborruso
Copy link

thank you

@andrii-rubtsov
Copy link

--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