Link to home
Start Free TrialLog in
Avatar of angelo_a
angelo_a

asked on

How to check if web page or image exists without downloading in ASP.NET

I need to check lots of URL's to see if the page or image that the URL points
to actually exists without downloading the actual page/file as this would be
very slow and consume lots of bandwith.

Is there a way to initiate a transfer of the page/image in chunks so that
I can check for a 404 error header so the entire page doesnt have to
be downloaded?

Thanks!
Avatar of sachiek
sachiek
Flag of Singapore image

I could see this example
http://www.w3coder.com/contest/examples/WSHttpReq.asmx

You can have something like this webservice.
Try to load the result into some simple xml document.
Look if "404 error" message is with inside that xml.

There might be whole lot of messages too like "host not found" etc.

Pretty much tuff. But give a short   :)


Sachi
Avatar of angelo_a
angelo_a

ASKER

That's but that's just a wrapper for doing a regular GET or POST request.
This would require downloading the entire image/page to get a response.

I'm looking for a way to request the image/page at a lower level so that
I can stop the transfer once enough info has been recieved to determine
if a valid image/page was returned or a 404 page was returned. This way
only the bare minimum data is transfered. The lists of URL's I need to check
can be from 2000-10000 URL's
I found what I needed to do this. In case anyone is interested, you set the
HttpWebRequest object's Method attribute to "HEAD" which returns only
the headers for the requested resource.

You then check the header via the HttpWebResponse.Headers collection.
With this you can check for a 404 and even see what type of resource it is.
Oh that is cool.

sachi
ASKER CERTIFIED SOLUTION
Avatar of PAQ_Man
PAQ_Man
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial