System.Net.WebException:使用WebRequest时操作超时

时间:2013-11-15 18:31:56

标签: c#

我收到WebException以下代码。我正在编写下面的简单代码来获取给定URI的响应流。

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://www.mist.ac.bd");
req.KeepAlive = true;
req.Timeout = 60000 * 2;

HttpWebResponse res = (HttpWebResponse)req.GetResponse();
Stream webData = res.GetResponseStream();

FileStream fs = new FileStream(Environment.SpecialFolder.Desktop + "sample.html", FileMode.Append, FileAccess.ReadWrite);

StreamWriter sw = new StreamWriter(fs);
sw.AutoFlush = true;
sw.WriteLine(webData.ToString());

我收到异常消息“请求已中止:操作已超时。”

我使用WebClient尝试了上述操作并得到了相同的错误。任何人都可以帮助我。

0 个答案:

没有答案