FAKE F# - 在 https 请求上启用 TLS

FAKE F# - enable TLS on https requests

我在 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。 我该如何解决?我怎样才能 select TLS1.2 only? 非常感谢这里的任何帮助!

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

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

您可以找到更多详细信息here