首页 > 解决方案 > FAKE F# - 在 https 请求上启用 TLS

问题描述

我在 F# 上有一些遗留代码

                let response = 
                    Http.Request (
                        ArtifactoryUrl, 
                        silentHttpErrors = true,
                        httpMethod = "POST", 
                        body = HttpRequestBody.TextRequest requestJson,
                        headers = [ 
                            HttpRequestHeaders.BasicAuth ArtifactoryUserName ArtifactoryPassword
                            HttpRequestHeaders.ContentType "application/json"
                            HttpRequestHeaders.Accept "application/json"
                        ]
                    )

从一段时间开始,它失败并出现以下错误

exception: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

我怀疑这是由于最近的网络服务器仅限于 TLS 1.2。我该如何解决?如何仅选择 TLS1.2?这里的任何帮助将不胜感激!

标签: tls1.2f#-fake

解决方案


我相信这是因为您使用的是旧版本的 .net 框架(低于 4.7)。如果是这样,您可以使用 ServicePointManager 为出站呼叫设置默认和回退版本:

ServicePointManager.SecurityProtocol <- SecurityProtocolType.Tls12 ||| SecurityProtocolType.Tls11

您可以在此处找到更多详细信息


推荐阅读