WebRequest and SSL (The underlying connection was closed. Could not establish trust relationship with remote server.)
internal class AcceptAllCertificatePolicy : ICertificatePolicy
{
public AcceptAllCertificatePolicy()
{
}
public bool CheckValidationResult(ServicePoint sPoint,
X509Certificate cert, WebRequest wRequest,int certProb)
{
// Always accept
return true;
}
}
Yep - that's what you need when you want to make sure that your programmatic SSL WebRequest accepts the SSL challenge. At least when you are encountering the Exception: "The underlying connection was closed. Could not establish trust relationship with remote server."
Before you call call the web request, you then set the static property CertificatePolicy on the ServicePointManager class like so:
ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
And that should work like a treat!