The SSL connection could not be established

后端 未结 3 1024
[愿得一人]
[愿得一人] 2020-12-14 08:06

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

相关标签:
3条回答
  • 2020-12-14 08:31
    ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) =>
    {
        // local dev, just approve all certs
        if (development) return true;
        return errors == SslPolicyErrors.None ;
    };
    

    This blog helped me

    https://www.khalidabuhakmeh.com/validate-ssl-certificate-with-servicepointmanager

    0 讨论(0)
  • 2020-12-14 08:38

    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)
    
    0 讨论(0)
  • 2020-12-14 08:44

    This worked for me,

    Create a Splunk.Client.Context by providing custom HttpClientHandler, that will bypass SSL invalid cert errors.

    HttpClientHandler handler = new HttpClientHandler();
    handler.ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => { return true; };
    
    // Create Context 
    Context context = new Context(Scheme.Https, "localhost", 8089, default(TimeSpan), handler);
    
    // Create Service
    service = new Service(context);
    
    0 讨论(0)
提交回复
热议问题