Tuesday, 18 August 2015

Hi Guys,

For http connection, the WebRequest and WebResponse classes use SSL to communicate with web hosts that support SSL. If the URI begins with "https:", SSL is used; if the URI begins with "http:", an unencrypted connection is used. We can also use HttpWebRequest/HttpWebResponse. But, It is an implementation specific to HTTP only.

Sometimes , HTTP validation is bad or contains corrupt certificates according to the .NET WebRequest class and we are not able to communicate well with the URL. At that time, we can ignore such certificate Error.

How do you tell HttpWebRequest/WebRequest to ignore certificate errors?


Two Ways:

A. Lambda expression

ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) => true);

B. Delegate

ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);

public bool AcceptAllCertifications(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certification, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
{
 return true;
}


You can put above line of code before you make the actual web request.

May be you will like to read below link as well

https://msdn.microsoft.com/en-us/library/system.net.servicepointmanager(v=vs.110).aspx


Thanks,
Chirayu Brahmbhatt 

No comments:

Post a Comment