我目前正在与由第三方创建的系统集成。该系统要求我使用XML/HTTPS发送请求。第三方寄给我的证书,我安装了它WebClient + HTTPS问题
我使用下面的代码:
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));
}
此代码返回以下WebException
:
基础连接已关闭:无法建立信任关系为SSL/TLS安全通道。
UPDATE因为这是我对工作的测试服务器,该证书不被信任和验证失败...要在测试/调试环境绕过这一点,创建一个新的ServerCertificateValidationCallback
ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(bypassAllCertificateStuff);
这里是我的 “假” 回调
private static bool bypassAllCertificateStuff(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error)
{
return true;
}
+1与您使用的代码更新。因为这个,很好的快速修复。 – 2010-08-31 20:06:37
调试SSL Web服务时,这非常有用,而不是将提琴手CA根注册到我的开发机器中!我只是在添加虚拟回调的部分放置了一个#if DEBUG,以便不将它放入生产代码中。 – jishi 2010-11-15 13:02:28
Go [here。](http://forums.asp.net/p/1174025/1972251.aspx) – Lonzo 2009-02-11 11:24:11