【发布时间】:2018-12-27 12:59:41
【问题描述】:
当我尝试使用 WebClient 连接到服务器时,有时会遇到此错误。
但是我已经完成了之前的问题和答案,例如Getting EOF exception over https call 关于这个。我已经尝试过他们的解决方案,但这对我没有帮助。
根据之前的问题,我还将 .net 框架从 4.5 更新到 4.6.1,但仍然面临同样的问题。
我的代码如下所示
private static string GetWebContent(string url)
{
string response = null;
try
{
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls | SecurityProtocolType.Ssl3;
using (var request = new GZipWebClient())
{
response = request.DownloadString(url);
request.Dispose();
}
}
catch (Exception ex)
{
throw ex;
}
return response;
}
【问题讨论】:
-
可能是的。由于缺乏声誉,我无法评论这个问题。我已经尝试过该解决方案,但这并没有解决我的问题。