Introduction
Here, we will see a simple way to make a request to a page of type SSL from C#, using the HttpWebRequest
class.
You can take this article as a reference: http://msdn2.microsoft.com/en-us/library/aa720131(VS.71).aspx.
Content
The first thing we must do is generate a class that implements the IcertificatePolicy
interface. The class will have the form:
public class MyPolicy : ICertificatePolicy
{
public bool CheckValidationResult(
ServicePoint srvPoint
, X509Certificate certificate
, WebRequest request
, int certificateProblem)
{
return true;
}
}
Next, to use this class, we must write:
System.Net.ServicePointManager.CertificatePolicy = new MyPolicy();
This call will be done before we instantiate the HttpWebRequest
class. Before we run the application, we must modify the machine.config file, which is in the %WINDIR%\Microsoft.NET\Framework\v1.1.4322\CONFIG directory. The modifications should be:
Find the node called servicePointManager
and modify the value of the checkCertificateName
attribute. This has the value true by default, and you must change the value to false. Then this node will look like this:
<servicePointManager checkCertificateName="false"
checkCertificateRevocationList="false"/>
Refer to Send a content type “multipart/form-data” request from C# for an example.