'how can i check if Website is currently available

I'm trying to get an exception when I try to download a file from a website. My current way is to download a .zip file from the website and check the file size of the .zip. I think that's not the best way to check if a website exists. Maybe some of you have a better idea for checking if a website is currently available, and if it isn't than get an error 404 exception.



Solution 1:[1]

It depends on what you want to achieve.

If you just want to know if there is something alive, just use a plain TCP socket and try to connection to port 80 (HTTP) or 443 (HTTPS). If the connection is successful, close it and assume a website is there.

If you want to be sure this is a website that responds, then you must issue an HTTP command that transfers the minimum data. You can send a HEAD command for that.

If you want to get a file, just try to get it, and check the status code for success or failure.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Remy Lebeau