无法建立 SSL 连接 [英] The SSL connection could not be established

查看:94
本文介绍了无法建立 SSL 连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 ASP.NET 核心应用程序中使用第三方库(Splunk c# SDK).我正在尝试通过此 SDK 连接到我的本地主机 Splunk 服务,但我收到一条异常消息:

I am using a third party library (Splunk c# SDK ) in my ASP.NET core application. I am trying to connect to my localhost Splunk service via this SDK, but I get an exception saying:

System.Net.Http.HttpRequestException: 无法建立 SSL 连接,请参阅内部异常.

System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception.

并且内部异常说:

根据验证程序,远程证书无效.

The remote certificate is invalid according to the validation procedure.

此 SDK 在底层使用 HTTP 客户端,但我无权访问此对象来配置 HttpClientHandler.

This SDK uses HTTP client under the hood, but I don't have access to this object to configure HttpClientHandler.

我在 google 上的所有搜索最终都使用 ServicePointManager 绕过 SSL 验证,但此解决方案在 Asp.Net 核心中不起作用.

All my search on google ends up using ServicePointManager to bypass the SSL validation, but this solution doesn't work in Asp.Net core.

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

有什么办法可以绕过asp.Net核心中的这种验证吗?

Is there any way to bypass this validation in asp.Net core?

推荐答案

是的,您可以使用以下代码绕过证书...

Yes, you can Bypass the certificate using below code...

HttpClientHandler clientHandler = new HttpClientHandler();
clientHandler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };

// Pass the handler to httpclient(from you are calling api)
HttpClient client = new HttpClient(clientHandler)

这篇关于无法建立 SSL 连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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