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

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

问题描述

我在ASP.NET核心应用程序中使用了第三方库( Splunk c#SDK )。我正在尝试通过此SDK连接到我的localhost 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天全站免登陆