The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

507 views
Skip to first unread message

Michael Guo

unread,
Jun 4, 2018, 5:35:56 AM6/4/18
to reCAPTCHA
Hi,

I used the reCaptcha v2.1 in my SharePoint project, but I got the error "The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.". Here is the link to connect to the recaptcha service "https://www.google.com/recaptcha/api/siteverify" and this code returned the error "using (var requestStream = webRequest.GetRequestStream())". If I added this code to bypass certificate and works. Anyone knows the reason.

Bypass code:

                System.Net.ServicePointManager.ServerCertificateValidationCallback +=
                    delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                                            System.Security.Cryptography.X509Certificates.X509Chain chain,
                                            System.Net.Security.SslPolicyErrors sslPolicyErrors)
                    {
                        return true; // **** Always accept
                    };

               using (var requestStream = webRequest.GetRequestStream())
                {
                    requestStream.Write(postDataBuffer, 0, postDataBuffer.Length);
                }

Thanks,

Michael
Reply all
Reply to author
Forward
0 new messages