Reputation: 919
I need to check if a remote file exists on a web server over HTTP that does not support HEAD requests (returns a 404 even if file exists). GET requests does return a 200 but I don't need to download the file which can be large. I also tried socket connections but they return 200 even if the file doesn't exist. Any suggestions on how to check if a remote URL exists efficiently? Thanks.
Upvotes: 1
Views: 579
Reputation: 15161
Well, you need to do a request to download the file but don't read the response stream. If you use HttpWebRequest, the request will be executed when the server has sent the headers, not the content of the file, so you can get the response, check the headers and dispose it, it will not download the full file, just some bytes while you were checking the headers.
Upvotes: 1