I'd like to send the
HTTP HEAD request using
wget. Is it possible?
There isn't any need for curl.
With Wget, adding
--spider implies that you want to send a
HEAD request (as opposed to
This is a great minimalistic way of checking if a URL responds or not. You can for example use this in scripted checks, and the
HEAD operation will make sure you do not put any load on neither the network nor the target webserver.
Bonus information: If Wget gets an HTTP error 500 from the server when it performs the
HEAD it will then move on to perform a
GET against the same URL. I don't know the reasoning for this design. This is the reason why you may see both a
HEAD and a
GET request being performed against the server. If nothing is wrong then only a
HEAD request is performed. You can disable this functionality with the
--tries option to limit Wget to only one attempt.
All in all, I recommend this for testing if an URL is responding:
# This works in Bash and derivatives wget_output=$(wget --spider --tries 1 $URL 2>&1) wget_exit_code=$? if [ $wget_exit_code -ne 0 ]; then # Something went wrong echo "$URL is not responding" echo "Output from wget: " echo "$wget_output" else echo "Check succeeded: $URL is responding" fi
--method=HTTP-Method For the purpose of RESTful scripting, Wget allows sending of other HTTP Methods without the need to explicitly set them using --header=Header-Line. Wget will use whatever string is passed to it after --method as the HTTP Method to the server.
Used the following in my bash script and can confirm it works as expected!
wget --method=HEAD https://www.website.com/