1

我正在使用 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

我不知道该错误是什么意思,也不知道如何解决。有什么猜测吗?

4

1 回答 1

-1

首先转换为 NetException(或类似的东西)以跟踪异常消息。发生这种情况可能有多种原因(例如不受支持的方法:))。如果网络异常没有什么特别之处,请检查防火墙或代理。如果您使用的是代理,请尝试通过代码或配置进行设置。

于 2012-07-12T21:58:46.447 回答