public static string LoadURL(this String url)
// usage:
// string myurl = "http://www.somewhere.net"; // don't forget http://
{
WebClient client = new WebClient();
// Add a user agent header in case the requested URI contains a query.
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
Stream data = client.OpenRead(url); <----- ERROR HAPPENS HERE, EXCEPTION
StreamReader reader = new StreamReader(data);
string urlContent = reader.ReadToEnd();
data.Close();
reader.Close();
return urlContent;
}
This is my code, for loading a 3rd party webpage.
Problem is, sometimes the remote host takes too long to respond, then I'm left with an exception.
System.Net.Sockets.SocketException: A connection attempt failed be ...
Go to the complete details ...