I know it is pretty simple to add a certificate to a HttpWebRequest. However, I have not found a way to do the equivalent using WebClient. Basicly, I want to send out a POST with a specific certificate using WebClient.
How would you accomplish this exact code using WebClient:
var request = (HttpWebRequest) WebRequest.Create("my-url");
request.Method = "POST";
request.ClientCertificates.Add(new X509Certificate()); //add cert
You must subclass and override one or more functions.
An interesting thing happened when a new certificate was installed on our front-ends. We started getting the error:
"The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.; The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.;"
We took care of the error by going to each front-end and opening the browser. It seems that IE was caching the old certificate. By opening the browsers, the new certificate took effect. Problem Solved!
Now you can with self signed cert ! ("The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.; The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.;")
Just subclass
WebClient
, add your ownClientCertificates
property and override theWebClient.GetWebRequest(System.Uri)
method. I don't have time to convert this to C# from VB but it should be fairly self-explanatory: