c# - 抛出尝试通过代码检查互联网连接时操作超时错误,在另一台电脑上工作正常
问题描述
我正在使用此代码在我的 C# 代码中检查互联网连接..
WebClient 工作站 = new WebClient();
字节[] 数据 = 工作站.DownloadData(" http://www.google.com ");
它在另一台电脑上运行良好(每次都返回结果),但在我的电脑上(Windows 7、64 位)有时会显示“操作超时错误”(System.Net.WebException)。这是电脑特有的问题吗,在不同的环境中尝试过,但没有得到任何线索..
解决方案
终于有办法了。。
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.DefaultConnectionLimit = 9999;
推荐阅读
- python - 如何在 wxpython 中获取 png 或 jpeg 或 bmp 图片
- python - Django - 为什么我不能检索用户名?
- javascript - 如何用新的图像替换图像,而不是在 API 提交后添加到页面?
- date - 日期、天数、周数、差异、培训和轮班开始公式
- sqlite - sqlite 内存数据库在执行之间持久化
- python - 用于在球体表面均匀分布点的万无一失的算法?
- r - 将 ggplotly() 图的图例设置为只有颜色而不是形状索引
- android-studio - 有什么方法可以计算 Android Studio 中微调器中的按钮点击次数?
- ruby - 红宝石中的尾递归在条件之前和之后产生总和?
- r - 如何在 R 中使用多个列表列展平数据框(从 BigQuery 加载)