Sending Client Certificate in HttpWebRequest
Posted
by Aaron Fischer
on Stack Overflow
See other posts from Stack Overflow
or by Aaron Fischer
Published on 2010-03-20T03:59:34Z
Indexed on
2010/03/20
4:01 UTC
Read the original article
Hit count: 876
x509certificate
|.net-3.5
I am trying to pass a client certificate to a server using the code below however I still revive the HTTP Error 403.7 - Forbidden: SSL client certificate is required. What are the possible reasons the HttpWebRequest would not send the client certificate?
var clientCertificate = new X509Certificate2( @"C:\Development\TestClient.pfx", "bob" );
HttpWebRequest tRequest = ( HttpWebRequest )WebRequest.Create( "https://ofxtest.com/ofxr.dll" );
tRequest.ClientCertificates.Add( clientCertificate );
tRequest.PreAuthenticate = true;
tRequest.KeepAlive = true;
tRequest.Credentials = CredentialCache.DefaultCredentials;
tRequest.Method = "POST";
var encoder = new ASCIIEncoding();
var requestData = encoder.GetBytes( "<OFX></OFX>" );
tRequest.GetRequestStream().Write( requestData, 0, requestData.Length );
tRequest.GetRequestStream().Close();
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback( CertPolicy.ValidateServerCertificate );
WriteResponse( tRequest.GetResponse() );
© Stack Overflow or respective owner