Created
August 3, 2020 11:26
-
-
Save ozzi-/78d4f8f125ed0fa357509b45c364b0e4 to your computer and use it in GitHub Desktop.
get response code, all headers, specific headers and response body from 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
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