C# HttpClient with X509Certificate2 - WebException: The request was aborted: Could not create SSL/TLS secure channel

前端 未结 2 1074
情歌与酒
情歌与酒 2021-01-17 05:02

I\'m working on implementing a payment service called Swish and testing it using this guide (Guide is in English even though filename is Swedish).

https://www.getswi

相关标签:
2条回答
  • 2021-01-17 05:21

    You can attach eventHandler to ServicePointManager like this:

    ServicePointManager.ServerCertificateValidationCallback = ForcedAuthDelegate;
    

    and implementation of ForcedAuthDelegate should return true to accept connection:

            static bool ForcedAuthDelegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
            {
                return true;
            }
    
    0 讨论(0)
  • 2021-01-17 05:24

    Found an SSL test performed on the server:

    https://www.ssllabs.com/ssltest/analyze.html?d=mss.swicpc.bankgirot.se

    From here I could see that the following protocols were allowed:

    After I set this everything worked:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    
    0 讨论(0)
提交回复
热议问题