N
news.microsoft.com
I want to make a boolean function to determine if a given URL is "alive",
where 'alive' means it does not result in DNS error, 404 error, or other
common errors.
I am currently using this code, but I'm not sure if it is the best way to do
it:
private bool IsURLAlive (string strURL)
{
WebClient myWebClient = new WebClient();
char[] buf = new char[128];
try
{
Stream myStream = myWebClient.OpenRead(strURL);
StreamReader sr = new StreamReader(myStream);
sr.ReadBlock(buf, 0, 127);
myStream.Close();
}
catch (System.Net.WebException webe)
{
return false;
}
return true;
}
I would like not to use exceptions, because I will be running a loop for,
say, 500 URLs.
Any ideas?
Thanks in advance,
Dan
where 'alive' means it does not result in DNS error, 404 error, or other
common errors.
I am currently using this code, but I'm not sure if it is the best way to do
it:
private bool IsURLAlive (string strURL)
{
WebClient myWebClient = new WebClient();
char[] buf = new char[128];
try
{
Stream myStream = myWebClient.OpenRead(strURL);
StreamReader sr = new StreamReader(myStream);
sr.ReadBlock(buf, 0, 127);
myStream.Close();
}
catch (System.Net.WebException webe)
{
return false;
}
return true;
}
I would like not to use exceptions, because I will be running a loop for,
say, 500 URLs.
Any ideas?
Thanks in advance,
Dan