0
我正在使用Webclient類下載網站HTML。代碼很簡單:無法從傳輸連接讀取數據:建立的連接被主機中的軟件中止
WebClient client = new WebClient();
client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
string web = client.DownloadString(url);
但是有時我會得到這個錯誤消息,我不能再現。它似乎隨機發生:
System.IO.IOException: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine
我不知道這個錯誤意味着什麼,或者我可以如何解決它。任何猜測?
你是否試過在使用語句中包裝WebClient? (不知道是否WebClient是一次性的或不...) – 2012-07-12 18:30:47
可能重複[建立的連接被您的主機中的軟件中止](http://stackoverflow.com/questions/1608431/an-established-connection-被軟件在你的主機中斷) – David 2012-07-12 18:31:59
@RobertH我處理這個類,我忘了粘貼這部分代碼。 – broke 2012-07-12 18:39:13