c# - 如何使用单声道解决 OSX 上的 SecureChannelFailure

标签 c# .net macos f# mono

我正在尝试访问 https://geocoder.cit.api.here.com在单声道上使用 .NET (F#)。我正在使用 FSharp.Data 中的 Http 帮助器,代码如下:

let baseUrl = "https://geocoder.cit.api.here.com/6.2/geocode.json?searchtext=1701%20McFarland%20Blvd%20E%20Tuscaloosa%09%20AL&app_id=<Some app id>&app_code=<Some app code>"

let res = Http.RequestString(baseUrl)

在单声道版本 4.6.2 的 OSX Sierra (10.12.2) 上为我运行此程序会产生 SecureChannelFailure。我该如何解决这个问题?我试过 mozroots --import --ask-remove 但没有用。 ~/.config/.mono/certs/Trust 中有证书。

我什至试图绕过检查,因为我只是在调查 API,但这也不起作用。我试图绕过它的方式是:

let callback = Security.RemoteCertificateValidationCallback(fun _ _ _ _ -> true)
ServicePointManager.ServerCertificateValidationCallback <- callback

最佳答案

使用 Mono 4.8+ 您可以分配环境变量 MONO_TLS_PROVIDERbtls在运行基于 CIL 之前 .exe :

export MONO_TLS_PROVIDER=btls
mono someFSharpAssembly.exe

通过 Xamarin Studio/Visual Studio for Mac 将其分配给运行配置:

enter image description here

如果你得到一个HttpRequestException :

Error: TrustFailure (Ssl error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED) ---> Mono.Btls.MonoBtlsException

It means that you do not have the certificates in the new format. Run the tool “btls-cert-sync” to convert your existing root certificates into the new file format. If “btls-cert-sync” complains that “The Old Trust Store does not exist”, you first need to tell Mono how to find these certificates, this page describes how to do it:

关于c# - 如何使用单声道解决 OSX 上的 SecureChannelFailure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41827960/

相关文章:

c# - 是否可以在 gridview 的单元格中滚动?

c# - 如何在类库中正确调用 P/Invoke 方法?

来自 C# 代码的 C# localdb SHRINKDATABASE 命令

c# - 发送网络请求时出现问题

c# - 在 C# 中,try-finally 如何捕获原始异常

.net - 我可以在 .NET 中重定向事件吗?

c# - 在一台 Mac 上输入电子邮件后,Azure AD 登录空白页面,在另一台上工作吗?

c# - 我应该在访问字典之前检查特定键是否存在于字典中吗?

python - 没有名为 igraph 的模块 - 错误

php - CakePHP 数据库连接 "Mysql"丢失,或无法创建