views:

407

answers:

2

ok. I know about the WebRequest and the WebResponse objects. The problem is that i do not really want to get the source code of the webpage, i only want to check to see if the link exists or not. The thing is, if i use the GetResponse method, it goes an pull the entire soource code of the site.

i am creating a broken link checker with many maNY MANY links. It takes quite a while to check them all. If there a way to to get MINIMAL information from a weblink? only enough information to see if the link is valid or broken (not the entire source code).

An answer (BESIDES USING ASYNCHRONOUS TRANSFER) would be greatly appreciated! :)

+4  A: 

A standard way of checking the existence of a link is to use a HEAD request, which causes the remote server to send the headers for the requested object, but not the object itself. If you thus requested an object that is not on the server, the server gives you the normal 404 response, but if it does exist, you get a 200 response and no data after the headers. This way very little uninteresting data goes over the wire.

TokenMacGuy
I don't know how to do that in C#, but I'm positive it is about as easy as a normal `GET` request.
TokenMacGuy
This might help. http://www.eggheadcafe.com/tutorials/aspnet/2c13cafc-be1c-4dd8-9129-f82f59991517/the-lowly-http-head-reque.aspx
Andy Gaskell
Thanks both you Dudes... dang you guys are fast
Jay
+4  A: 
 WebRequest request = HttpWebRequest.Create("http://www.foo.com/");
 request.Method = "HEAD"; // Just get the document headers, not the data.

HEAD is similar to GET, only that instead of getting the file contents, we get just the headers.

Anwar Chandra
Thanks both you Dudes... dang you guys are fast. Thnx for the code example
Jay
+1 there's no good reason why this answer is lower rep than mine.
TokenMacGuy