Why I always get 'The operation has timed-out.' exception from some pages?

  • Thread starter Thread starter Andy Chen
  • Start date Start date
A

Andy Chen

Hi all,

Please help me to look at the following code, I always get a 'The operation
has timed-out.' exception. But the URL can be opened in IE properly. I am
wondering if I missed some code. Any help would appreciate!!

HttpWebRequest httpReq;
HttpWebResponse httpResp;
try
{
httpReq =
(HttpWebRequest)WebRequest.Create("http://safety.live.com);
httpReq.Timeout = 10000;
httpReq.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT
5.1; .NET CLR 1.0.3705";
httpReq.ContentType = "application/x-www-form-urlencoded";
httpResp = (HttpWebResponse) httpReq.GetResponse();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
}
 
Where is the code running from?

If this is an ASP.NET app the your code will be running under the ASPNET
user on the server and I'm guessing if you are in an office your firewall is
blocking the connection?
 
Back
Top