Error: 'System.Net.ServicePointManager.CertificatePolicy' is obsolete: 'CertificatePolicy is obsoleted for this type, please use ServerCertificateValidationCallback instead.' http://go.microsoft.com/fwlink/?linkid=14202
Solution:
Change the below line
ServicePointManager.CertificatePolicy = new CustomCertificatePolicy();
to
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CertValidation);
bool CertValidation(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyErrors)
{
bool result = false;
// TODO: implement
return result;
}
Alternative: If you want to accept untrusted server certificate which I don't recommend :D .. replace the above function to the function below to the class.
bool CertValidation(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslpolicyErrors)
{
bool result = false;
if ((chain != null) && (chain.ChainStatus.Length == 1) &&
(chain.ChainStatus[0].Status == X509ChainStatusFlags.UntrustedRoot))
result = true;
return result ? result : sslpolicyErrors == SslPolicyErrors.None;
}