20 June 2007

Check if url is alive, some code

private static bool IsURLAlive(string strURL)
{

using (WebClient myWebClient = new WebClient())
{
char[] buf = new char[128];
try
{
using ( Stream myStream = myWebClient.OpenRead(strURL) )
{
StreamReader sr = new StreamReader(myStream);
sr.ReadBlock(buf , 0 , 127);
myStream.Close();
}
}
catch ( WebException webe )
{
return false;
}
return true;
}

}

1 comment:

Anonymous said...

There is no need to perform a GET request, since it returns the complete body.. just do a HEAD one..