Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Send a request to an SSL page from C#

0.00/5 (No votes)
2 Feb 2007 1  
Send a request to an SSL page from C#

Introduction

Here we will describe the simple way that you will use to make a request to one page of type SSL from C#, using HttpWebRequest class.

Taking as refence the article published in the web : http://msdn2.microsoft.com/en-us/library/aa720131(VS.71).aspx .

Content

The first we must do is generate one class that implement the IcertificatePolicy interface, the class will have the next form :

"cs">
public class MyPolicy : ICertificatePolicy 
{ 
    public bool CheckValidationResult( 
            ServicePoint srvPoint 
            , X509Certificate certificate 
            , WebRequest request 
            , int certificateProblem) 
    { 
        //Return True to force the certificate to be accepted. 

        return true; 
    } // end CheckValidationResult 

} 
Next, to use this class we must write next text line :
"cs">//Set certificatePolicy. 

System.Net.ServicePointManager.CertificatePolicy = new MyPolicy(); 
This call will be do before of the instance of the HttpWebRequest class. Before run the application, you must modify the machine.config file, this is in the %WINDIR%\Microsoft.NET\Framework\v1.1.4322\CONFIG directory.
The modifications are :

Find the node called servicePointManager and modify the value of the checkCertificateName attribute , this have the value in true by default and you must change this value to false. Then this node will look like this :

"xml"><servicePointManager checkCertificateName="false" checkCertificateRevocationList="false"/> 

Refer to multipart_request_C_.asp for example.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here