Skip to content

Instantly share code, notes, and snippets.

@ozzi-
Created August 3, 2020 11:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozzi-/78d4f8f125ed0fa357509b45c364b0e4 to your computer and use it in GitHub Desktop.
Save ozzi-/78d4f8f125ed0fa357509b45c364b0e4 to your computer and use it in GitHub Desktop.
get response code, all headers, specific headers and response body from CURL
res=$(curl "https://zgheb.com" -i -sS -w "\r\n%{http_code}")
responseCode=$(echo "$res" | tail -1)
headersAndBody=$(echo "$res" | head -n -1)
headers=$(echo "$headersAndBody" | awk '{if($0=="\r")exit;print}')
body=$(echo "$headersAndBody" | awk '{if(body)print;if($0=="\r")body=1}')
powered=$(echo "$res" | grep -Fi "X-Powered-By" | cut -d ":" -f2 | awk '{$1=$1};1')
echo "Response Code:"
echo $responseCode
echo "----------------"
echo "Headers:"
echo "$headers"
echo "----------------"
echo "Header Value of X-Powered-By:"
echo $powered
echo "----------------"
echo "Body:"
echo $body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment