Hi, I'm trying to write an application that gets stock quotes from Google Finance and graphs them, in C#. My program uses the HttpWebRequest class to request the source code for the web page containing the stock quote, about every thirty seconds. After getting the source, I then extract the quotes and graph them.
My issue is that when the program goes about requesting every 30 seconds, about 50% of the time I invoke "objWebReq.GetResponse()", I get timeout exceptions! I checked my internet connection, and I'm absolutely sure that I'm connected when the timeout exceptions occur. Is there something I'm not doing correctly, that would cause Google to occasionally reject my request? Here is the portion of my program that makes the request for the source code.
//Create and configure object for request
HttpWebRequest objWebReq = (HttpWebRequest)WebRequest.Create(url); //Valid URL
objWebReq.Timeout = MSWAIT; //Set to 10 seconds
objWebReq.Method = "GET";
objWebReq.ContentType = "text/html";
objWebReq.KeepAlive = false;
objWebReq.Referer = "http://www.google.com/finance";
objWebReq.UserAgent =
"Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko/20100115
Firefox/3.6";
StreamReader objStream = null;
//Create Object for the response.
try
{
HttpWebResponse objWebResp = (HttpWebResponse)objWebReq.GetResponse();
objStream = new StreamReader(objWebResp.GetResponseStream(),
System.Text.Encoding.ASCII);
}
catch
{
//Do Nothing
}
return objStream;
}