I am currently integrating with a third party system. This system requires me to send a request using XML / HTTPS. The third participant sent me a certificate and I installed it
I am using the following code:
using (WebClient client = new WebClient()) { client.Headers.Add(HttpRequestHeader.ContentType, "text/xml"); System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding(); var response = client.UploadData(address, "POST", encoding.GetBytes(msg)); }
This code returns the following WebException :
The connected connection was closed: Failed to establish trust for the SSL / TLS secure channel.
UPDATE Since this is the test server I'm working with, the certificate is not trusted and verification fails ... To get around this in the testing / debugging environment, create a new ServerCertificateValidationCallback
ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(bypassAllCertificateStuff);
and here is my "fake" callback
private static bool bypassAllCertificateStuff(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error) { return true; }
More here and here
rudigrobler Feb 11 '09 at 11:15 2009-02-11 11:15
source share