c# - 使用 TLS 1.2 从 HttpClient 连接到 Azure FrontDoor 后面的 API

标签 c# .net azure tls1.2 azure-front-door

Azure Front Door 配置为最低 TLS 1.2。 后端 Azure 应用服务还配置为使用最低 TLS 1.2。

在 Windows Server 2012 R2 上使用以下代码运行 .Net Framework 4.7.1 控制台应用程序时:

class Program
    {
        static async Task Main(string[] args)
        {
             ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
             var client = new HttpClient();

            try
            {

                var OK = await client.GetAsync("https://foo-appservice.azurewebsites.net/"); // App service.
                var NotOK = await client.GetAsync("https://foo.myfoo.io/"); // Front door.

            }
            catch (Exception e)
            {
               Console.WriteLine(e);
            }

            Console.ReadKey();
        }
    }

我在第二次调用时遇到以下异常。

An error occurred while sending the request.
The underlying connection was closed: An unexpected error occurred on a send.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

但是,使用同一服务器上的curl 运行它是可行的:

curl https://foo.myfoo.io/ -i --tlsv1.2 --tls-max 1.2

相同的 .net 代码在我的其他 Windows 10 笔记本电脑上运行良好。

Windows服务器上调用失败的原因是什么?

编辑:

我认为这与自定义域有关,因为对前门分配的域执行简单的 GET 是可行的。

最佳答案

事实证明“有人”禁用了 Windows Server 上的许多密码套件。

我使用wireshark查看TLS握手,并注意到客户端Hello中列出的密码套件与服务器不匹配。

因此,对于任何遇到 TLS 错误的人来说,查看 Wireshark 中的 TLS 握手是值得的!

关于c# - 使用 TLS 1.2 从 HttpClient 连接到 Azure FrontDoor 后面的 API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60320835/

相关文章:

azure - 如何在Azure API管理Python SDK中使用过滤器

azure - 如何避免 KQL 查询中的数据点过多 (10000)?

c# - 将 24 位值转换为 float 并返回

c# - 如何在 Symbian 上编写程序?

c# - 统一类型系统有助于垃圾收集吗

c# - 在 API 中使用任务并行库

c# - 在 Windows 窗体中的文本标签中输入 "&"符号?

c# - 在 C#/WPF 中构建共享代码库的技巧/资源?

Azure Web App .NET Core 启动错误 - 如何查找原因

c# - 查询或数据库错误