使用 couchbase dotnet sdk 时,MacOS 上的 DotNet core 2.0 获取由 httpclient 触发的 libcurl 和 ssl 错误 [英] DotNet core 2.0 on MacOS gets libcurl and ssl error triggered by httpclient when using couchbase dotnet sdk

查看:17
本文介绍了使用 couchbase dotnet sdk 时,MacOS 上的 DotNet core 2.0 获取由 httpclient 触发的 libcurl 和 ssl 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Dotnet core 2.x(实际上使用的是 2.1.4,我写这篇文章时的最新版本)web api 项目,为了使用 couchbase 作为我的数据库服务器,我需要使用 couchbase SDK.sdk 声明它支持 DotNet 核心 2.x.

I am developing an Dotnet core 2.x(actually using 2.1.4, latest release when I'm writing this) web api project, in order to use couchbase as my database server, I need to use the couchbase SDK. The sdk states that it supports DotNet core 2.x.

在进行了非常基本的设置后,我只想测试连接性,但不断收到此错误.

After a very basic setup and I just want to test the connectivity, I keep getting this error.

HttpRequestException:处理程序不支持使用 libcurl (7.54.0) 及其 SSL 后端 ("LibreSSL/2.0.20") 的这种组合自定义处理证书.

HttpRequestException: The handler does not support custom handling of certificates with this combination of libcurl (7.54.0) and its SSL backend ("LibreSSL/2.0.20").

我认为这是 couchbase SDK 的问题,但经过一番研究,我发现它与 macOS 内置的 openssl 和 curl 不支持某些行为有关.以下是一些参考:

I thought this is a issue with the couchbase SDK, but after some research, I found it is about the macOS built-in openssl and curl does not support certain behavior. Here are some reference:

.NET Core、OSX、libcurl、和 OpenSSL

Couchbase dotnet SDK OSX libcurl 错误

经过更多研究,事实证明 dotnet core 2.0 应该不再受 MacOS 相关问题的困扰...但为什么我仍然会遇到这个问题?

after some more research, it turns out that dotnet core 2.0 should no longer suffer from the MacOS related issue...But why am I still getting this?

是否有任何解决方法,例如告诉 HttpClient 使用 curl 的 brew 版本?

Is there any workaround like telling HttpClient to use brew version of curl?

推荐答案

使用 Socket HTTP Handler 的步骤

这是我需要做的才能让它工作:

Steps to Use Socket HTTP Handler

Here's what I needed to do to get this to work:

  • 安装 .NET Core SDK 2.1.xxx-preview
  • 更新项目 AspNetCore.All 参考
  • 将包源添加到 NuGet.Config
  • 设置环境变量

下载并安装macOS 安装程序

更新包参考:

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.1.0-preview1-final" />

将包源添加到 NuGet.Config

更新 ~/.nuget/NuGet/NuGet.Config 并添加另一个包源:

<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />

我需要这样做,因为我收到了 NuGet 错误:错误 NU1102:无法找到版本为 (>= 2.1.0) 的软件包 Microsoft.AspNetCore.All.

I needed to do this because I was getting a NuGet error: error NU1102: Unable to find package Microsoft.AspNetCore.All with version (>= 2.1.0).

在我的 Startup.cs 中,我设置了一个环境变量:

In my Startup.cs I set an environment variable:

Environment.SetEnvironmentVariable("DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER", "true");

我们在做什么

在 2.1 dotnet 中,将包含自己的 Socket 处理程序,绕过操作系统特定的处理程序,因此我们可以避免 macOS 问题.在 preview-1 中,我们仍然必须手动选择加入:https://github.com/dotnet/corefx/blob/master/src/System.Net.Http/src/System/Net/Http/HttpClientHandler.cs

但很快会在 preview-2 中默认开启:https://github.com/dotnet/corefx/pull/27821

But soon in preview-2 it'll be on by default: https://github.com/dotnet/corefx/pull/27821

今天早上我一直在调查同样的问题,目前我认为没有明确的解决方案.Dotnet Core 2.x 没有解决 Couchbase SDK 的问题,但我认为在 Couchbase 之外使用 HttpClient 很好(尚未对此进行测试).

I've been investigating the same issue this morning and I currently don't think there's a clear solution. Dotnet Core 2.x does not resolve the issue for the Couchbase SDK, though I think using HttpClient outside of Couchbase is fine (haven't tested this).

从 Couchbase SDK 版本 2.5.8(2018 年 3 月 17 日)开始,这仍然是一个已知问题:https://developer.couchbase.com/server/其他产品/release-notes-archives/dotnet-sdk

As of Couchbase SDK Version 2.5.8 (17 March 2018) this is still a known issue: https://developer.couchbase.com/server/other-products/release-notes-archives/dotnet-sdk

实际问题链接:https://issues.couchbase.com/browse/NCBC-1296

在论坛中,请参阅:

如果找到可行的解决方案,我会回帖.

I'll post back if I find a working solution.

这篇关于使用 couchbase dotnet sdk 时,MacOS 上的 DotNet core 2.0 获取由 httpclient 触发的 libcurl 和 ssl 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆