I use WebRequest to check for the presence of a web page or media (image). In GetResponse, I get a System.Net.WebException exception. I ran 100 links and it seems to me that it is going slower than necessary. Is there a way to not get this exception or handle it more elegantly?
static public bool CheckExist(string url)
{
HttpWebRequest wreq = null;
HttpWebResponse wresp = null;
bool ret = false;
try
{
wreq = (HttpWebRequest)WebRequest.Create(url);
wreq.KeepAlive = true;
wresp = (HttpWebResponse)wreq.GetResponse();
ret = true;
}
catch (System.Net.WebException)
{
}
finally
{
if (wresp != null)
wresp.Close();
}
return ret;
}
user34537
source
share