1

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.

1
  • Maybe download only 1 MB, and assume, if the file is larger, the file exist? Commented Feb 6, 2016 at 23:29

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

HttpWebRequest would be GET? OP says, there are wrong headers.
HttpWebRequest will be of the type the OP sets, so it can be GET POST or anything the server expects, just roll the same request as if you were downloading the file.
My bad, the wrong 200 Code was not related to GET. +1
Thank you for your reply, @Gusman. I'm trying your suggestion but the response is still being downloaded in its entirety. Do you mind providing a code snippet showing the usage of HttpWebRequest? Thanks.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.