由于以下错误消息,我们无法使用WebRequest
连接到HTTPS服务器:
The request was aborted: Could not create SSL/TLS secure channel.
我们知道服务器没有使用路径的有效HTTPS证书,但为了绕过此问题,我们使用以下代码,这些代码取自另一个StackOverflow帖子:
private void Somewhere() {
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(AlwaysGoodCertificate);
}
private static bool AlwaysGoodCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors) {
return true;
}
问题是服务器从未验证证书,并失败,并出现上述错误.有人知道我应该怎么做吗?
值得一提的是,我和一位同事在几周前进行了测试,使用类似于我上面所写的内容,它工作得很好.我们发现的唯一"主要区别"是我使用的是Windows7,而他使用的是Windows XP.这会改变什么吗?