HTTPs Client to connect to server without trusted chain (non trusted CA) on Azure Web App

前端 未结 1 1527
灰色年华
灰色年华 2021-01-21 22:27

I have been stuck for around 3 days trying to connect to a server that has a certificate which hasn\'t been signed by a trusted CA - you can add the CA\'s certificate through Az

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-21 23:00

    What about hardcode returning true in your custom callback like this?

     public string Ssl()
        {
            try
            {
                ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;
                using (var wc = new WebClient())
                {
                    var res = wc.DownloadString("https://untrusted-root.badssl.com/");
                    Console.WriteLine(res);
                    return res;
                }
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }
    

    0 讨论(0)
提交回复
热议问题