首页 > 解决方案 > 抛出尝试通过代码检查互联网连接时操作超时错误,在另一台电脑上工作正常

问题描述

我正在使用此代码在我的 C# 代码中检查互联网连接..

WebClient 工作站 = new WebClient();

字节[] 数据 = 工作站.DownloadData(" http://www.google.com ");

它在另一台电脑上运行良好(每次都返回结果),但在我的电脑上(Windows 7、64 位)有时会显示“操作超时错误”(System.Net.WebException)。这是电脑特有的问题吗,在不同的环境中尝试过,但没有得到任何线索..

标签: c#.net

解决方案


终于有办法了。。

ServicePointManager.Expect100Continue = true;

ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;

ServicePointManager.DefaultConnectionLimit = 9999;


推荐阅读