2013-11-26 88 views
1

升級到Windows 8後,我遇到了以前工作的Web服務調用問題。我已經在兩臺Windows 8.1計算機和一臺Windows 8計算機上驗證了以下代碼失敗,但在Windows 7和Windows Server 2008 R2上運行時沒有錯誤。錯誤:無法創建SSL/TLS安全通道Windows 8

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.

這似乎是定位於這個端點,因爲我能夠成功地使SSL調用其他網址。我已經做了一些Wireshark嗅探,但不知道要尋找什麼,這沒什麼幫助。如果您希望我也提供這些日誌,請告訴我。

回答

1

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; 
} 
+1

這有效,但爲什麼? Windows 8中改變了什麼? –

+0

SSL3已被棄用,所以使用時請小心! –

相關問題