Tuesday, June 21, 2011

Bypass SSL security in C# WebClient

If you are using WebClient in C# and getting following error,
"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel."

and you want to bypass the SSL certificate security, just use this code to bypass the security check, before calling client.OpenRead method

ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(
delegate
{
return true;
});