HttpWebResponse返回无法在Windows 10 Redstone中创建SSL / TLS安全通道

时间:2016-06-14 14:38:59

标签: c# windows cisco

在测试我们的一些应用程序与Windows 10的兼容性时(特别是在预览上确保所有内容都适用于下个月的周年纪念更新),我们发现我们的呼叫中心应用程序不再连接。当前的Windows预览版本为14361。

我们收到WebException声明:请求已中止:无法创建SSL / TLS安全通道。

我在这里查找了一些其他类似的答案,说要强制使用TLS1.2,或者启用跟踪以查看是否正在生成HTTP错误。

以下是跟踪结果:

System.Net.Sockets Verbose: 0 : [11344] Exiting Socket#60270212::Receive()  -> Int32#4383
System.Net Information: 0 : [11344] InitializeSecurityContext(credential =     System.Net.SafeFreeCredential_SECURITY, context = 15eda00:a93eed8, targetName = servernameredacted, inFlags = ReplayDetect, SequenceDetect, Confidentiality, AllocateMemory, InitManualCredValidation)
System.Net Information: 0 : [11344] InitializeSecurityContext(In-Buffers count=2, Out-Buffer length=0, returned code=InternalError).
System.Net.Sockets Verbose: 0 : [11344] Socket#60270212::Dispose()
System.Net Error: 0 : [11344] Exception in HttpWebRequest#14000148:: - The request was aborted: Could not create SSL/TLS secure channel..
System.Net Error: 0 : [11344] Exception in HttpWebRequest#14000148::GetResponse - The request was aborted: Could not create SSL/TLS secure channel..

以下是相关代码段:

public static string PerformAPIOperation(HTTPOperation operation, string uriP2, string xmlData, string postData = "")
    {

        //test to fix issue in win10ani
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

        try
        {
            if (uriP2.ToLower().Contains("/finesse/api/"))
            {
                //trim off the parts we are already expecting
                uriP2 = uriP2.Split(new string[] { "/finesse/api/" }, StringSplitOptions.RemoveEmptyEntries)[0];
            }
            //create webrequest, using https if set
            HttpWebRequest request = WebRequest.Create((mainSettings.useHTTPS) ? string.Format(connectURIHTTPS, mainSettings.FQDN, uriP2) : string.Format(connectURIHTTP, mainSettings.FQDN, uriP2)) as HttpWebRequest;
            request.CookieContainer = cookieJar;
            request.Method = operation.ToString();

            if (postData != string.Empty)
            {
                request.Headers.Add("Authorization", "Basic " + postData);
            }

            if (operation != HTTPOperation.GET)
            {
                using (Stream stream = request.GetRequestStream())
                {
                    char[] reqData = xmlData.ToCharArray();
                    byte[] byteStream = Encoding.UTF8.GetBytes(reqData);

                    request.ContentType = "application/xml";
                    stream.Write(byteStream, 0, byteStream.Length);
                }
            }

            HttpWebResponse response = request.GetResponse() as HttpWebResponse;

            using (StreamReader sr = new StreamReader(response.GetResponseStream()))
            {
                return sr.ReadToEnd();
            }
        }
        catch (Exception ex)
        {
            if (ex is WebException)
            {
                HttpWebResponse resp2 = ((WebException)ex).Response as HttpWebResponse;
                string response = string.Empty;
                using (StreamReader sr = new StreamReader(resp2.GetResponseStream()))
                {
                    response = sr.ReadToEnd();
                }
                using (_sw = new StreamWriter(mainSettings.GetSaveLocation(false) + @"WEBLOGGING\error.log", true))
                {
                    _sw.WriteLine(System.DateTime.Now.ToLongDateString() + " " + System.DateTime.Now.ToLongTimeString());
                    _sw.WriteLine(response);
                    _sw.WriteLine();
                }

                return response;
            }
            else return string.Empty;
        }
    }

0 个答案:

没有答案