WebRequest.GetResponse() is one of the most common ways we adopt to perform a HTTPWebRequest from our server side. This case was a specific one, although the error appeared to be more generic in nature. In fact it happened only in SharePoint and not in my .Net application.
The error observed in the GetResponse() method was:
“The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel”
One of the root cause of this problem is due to the certificate issue. And to be more precise the certificate validation has failed.
The solution to this problem, more or less i would call it a decent workaround is to use the ServerCertificateCallbackValidation method from the HttpWebRequest class and forcefully return true.
Create a static method for validating the certificate
private static bool ValidateFbCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)
Just before u make your HttpWebRequest try using this.
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(ValidateFbCertificate);
This should skip any certificate errors.