Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Use of Client Certificate by HttpWebRequest

9 views
Skip to first unread message

EagleRedHighF...@discussions.microsoft.com

unread,
Aug 25, 2009, 6:24:11 PM8/25/09
to
I am writing an application to pull XML data via HTTPS. I have a client
certificate that I can use interactively, but I must automate the sessions.
I exported the public key to a .cer file.


// Create a 'WebRequest' object with the specified url.
string url = "..."; // The url with a querystring
HttpWebRequest myWebRequest = (HttpWebRequest)WebRequest.Create(url);
X509Certificate Cert = X509Certificate.CreateFromCertFile("userCert.cer");
myWebRequest.Method = "POST";
myWebRequest.ClientCertificates.Add(Cert);

// Send the 'WebRequest' and wait for response.
WebResponse myWebResponse = myWebRequest.GetResponse();

The GetResponse throws an exception with the message, "The underlying
connection was closed: Could not establish trust relationship for the SSL/TLS
secure channel."

The certificate is good because I can connect interactively, but with some
certificate issues. The certificate is self-signed without a root authority.
How can I get this work?

As always, thanks,
Eagle

0 new messages