升级到 Windows 8 后,我在使用以前工作的 Web 服务调用时遇到问题。我已经在两台 Windows 8.1 机器和一台 Windows 8 机器上验证了以下代码失败,但它在 Windows 7 和 Windows Server 2008 R2 上运行没有错误。
var uriString = "https://secure.unitedmileageplus.com/";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriString);
try {
using(WebResponse response = request.GetResponse()) {
response.Dump();
}
}
catch(Exception e) {
e.Dump();
}
WebException The request was aborted: Could not create SSL/TLS secure channel.
它似乎已本地化到此端点,因为我能够成功地对其他 URL 进行 SSL 调用。我已经完成了一些 Wireshark 嗅探,但不知道要寻找什么,这没什么帮助。如果您希望我也提供这些日志,请告诉我。
最佳答案
WebRequest
默认将 TLS/SSL 版本设置为 TLS 1.0。您可以使用 ServicePointManager.SecurityProtocol
将其设置回 SSL 3.0。例如:
static void Main(string[] args)
{
var uriString = "https://secure.unitedmileageplus.com/";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriString);
ServicePointManager.ServerCertificateValidationCallback =
new RemoteCertificateValidationCallback(AcceptAllCertifications);
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
try
{
using (WebResponse response = request.GetResponse())
{
Debug.WriteLine(response);
}
}
catch (Exception e)
{
Debug.WriteLine(e);
}
}
public static bool AcceptAllCertifications(
object sender,
System.Security.Cryptography.X509Certificates.X509Certificate certification,
System.Security.Cryptography.X509Certificates.X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
}
关于.net - 错误 : Could not create SSL/TLS secure channel Windows 8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20228656/