C#控制台应用程序HttpClient抛出“ System.Net.Http.WinHttpException:发生安全错误”

问题描述 投票:0回答:1

我有一个Windows Server 2012 R2中运行.NET Framework 4.6的C#控制台应用程序。我正在使用“ IIS Crypto 3.1”来更改安全协议中的某些设置,但是在使用“ IIS Crypto”中的“最佳实践”功能(自动设置客户端和服务器协议)后,我无法使应用程序调用任何再次通过HttpClient的URL(以前曾经工作过)。这是我的代码:

 using (HttpClient hc = new HttpClient())
  {
      ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 
      | SecurityProtocolType.Tls;

       ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, 
       errors) => { return true; };
       var response = await hc.GetAsync(download_path);
       content = response.Content;
   }

这是我碰到“ hc.GetAsync()”后立即得到的异常:

System.AggregateException: One or more errors occurred. ---> System.AggregateExc
eption: One or more errors occurred. ---> System.Net.Http.HttpRequestException:
An error occurred while sending the request. ---> System.Net.Http.WinHttpExcepti
on: A security error occurred

这是我的安全协议的当前设置:

enter image description here

不幸的是,我不知道如何还原在此更改的设置(此应用程序更改了某些注册表项。)>

更新:

因此,问题似乎仅在为Telegram Bot API调用特定URL时出现(它类似于https://api.telegram.org/....。)。对于其他网址(据我所知),整个新设置仍然可以使用。我必须说,以前的设置可以很好地使用此相同的URL。

我有一个Windows Server 2012 R2中运行.NET Framework 4.6的C#控制台应用程序。我正在使用“ IIS Crypto 3.1”来更改安全协议中的某些设置,但在使用...

c# .net console-application dotnet-httpclient windows-server-2012-r2
1个回答
0
投票

经过7个小时的不懈努力,我终于找到了问题所在。显然,“ IIS Crypto”已更改Windows Server 2012 R2中“密码套件”的顺序。我只是启用/禁用协议本身,而不是密码顺序。将密码套件的顺序更改为其默认顺序后(请注意,此顺序是特定于操作系统的。因此,在Windows Server 2008、2012、2016,...中它有所不同,并且我在“ IIS Crypto”网页中找到了默认值。)看来Telegram服务器对密码套件的顺序很敏感,并且在更改时不响应(我不知道此处的确切技术)。所以这就是它在Windows Server 2012 R2中的外观:

© www.soinside.com 2019 - 2024. All rights reserved.