升级到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请求已中止:无法创建SSL / TLS安全 信道。
它似乎已本地化到此端点,因为我能够成功地对其他URL进行SSL调用。我已经做了一些Wireshark嗅探,但不知道该寻找什么,它没有多大帮助。如果您希望我提供这些日志,请告诉我。
答案 0 :(得分:1)
WebRequest
默认情况下将TLS / SSL版本设置为TLS 1.0。您可以使用ServicePointManager.SecurityProtocol
将其设置回SSL 3.0。 E.g:
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;
}