【发布时间】:2020-04-04 12:53:58
【问题描述】:
我有一个在 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
这是我的安全协议的当前设置:
很遗憾,我不知道如何恢复我在此处更改的设置(此应用更改了一些注册表项)。
更新:
所以问题似乎只在调用 Telegram Bot API 的特定 URL 时出现(类似于 https://api.telegram.org/.....)。对于其他 URL(据我所知),这个全新的设置仍然有效。我必须说,之前的设置完全适用于这个相同的 URL。
【问题讨论】:
-
download_path ..... 这是 https 吗?还是只是 http?
-
@JonathanAlfaro 是的,它是 Telegram Bot API 的 https 地址。我实际上是在连续试用 7 小时后才发现问题的。我会更新帖子并相应地回答。简而言之,问题在于我在使用“IIS Crypto”后更改的“密码套件”顺序。将更改恢复为默认顺序将对问题进行排序。
标签: c# .net console-application dotnet-httpclient windows-server-2012-r2