Thursday, April 21, 2011

Get HTTP status code with curl in bash


curl --write-out %{http_code} --silent --output /dev/null URL

and then wrapping it into a function

getHTTPCode () {
echo $(curl --write-out %{http_code} --silent --output /dev/null $1)
}

response=$(getHTTPCode URL)
echo $response

No comments:

Post a Comment