Search code examples
vb.netsystem.net.httpwebrequest

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


I been struggling with this error for more than a week. i tried all the possible solutions but couldn't find it . I am calling a web service to get the data. Everything works fine for the first time but after 5 minutes if I do the process again it is throwing me an error

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

Please find me out a solution for it. I am using a API call to quickbase and i am using System.Net.http for calling the http client. It is throwing the exception at the first API call made by the program


Solution

  • I have solved the problem . we should be giving permission to the program to accept the certificates. Add the below code where it is reaching for certificate. Net.ServicePointManager.ServerCertificateValidationCallback = AddressOf ValidateRemoteCertificate Now call the below function. This is can be security issues but it is a work around.

     Public Shared Function ValidateRemoteCertificate(sender As Object, certificate As X509Certificate, chain As X509Chain, sslPolicyErrors As SslPolicyErrors) As Boolean
        Return True
    End Function