C# 获取请求错误“;无法创建SSL/TLS安全通道“;

C# 获取请求错误“;无法创建SSL/TLS安全通道“;,c#,.net-core,frameworks,C#,.net Core,Frameworks,我尝试从ConsoleApp请求站点页面: static void Main(string[] args) { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; var handler = new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZi

我尝试从ConsoleApp请求站点页面:

static void Main(string[] args)
    {
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        var handler = new HttpClientHandler
        {
            AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
            ,
            AllowAutoRedirect = false
        };

        using (var client = new HttpClient(handler))
        {
            var response = client.GetAsync("https://lk.fssprus.ru/ds_cabinet/action/login");
            var httpResponseMessage = response.Result;
            var content = httpResponseMessage.Content.ReadAsStringAsync();
            Console.WriteLine(content.Result);
        }
        Console.ReadKey();
    }
并获取以下错误:

System.AggregateException HResult=0x80131500消息=发生了一个或多个错误。Source=mscorlib StackTrace:at System.Threading.Tasks.Task.ThrowifeException(布尔值 includeTaskCanceledExceptions)位于 System.Threading.Tasks.Task
1.GetResultCore(布尔值
waitCompletionNotification)位于
System.Threading.Tasks.Task
1.在 中的ConsoleApp8.Program.Main(字符串[]args) C:\Projects\FsspConnectTest\ConsoleApp8\Program.cs:第26行

此异常最初是在此调用堆栈中引发的: System.Net.HttpWebRequest.EndGetResponse(System.IAsyncResult) System.Net.Http.HttpClientHandler.GetResponseCallback(System.IAsyncResult)

内部异常1:HttpRequestException:运行时出错 发送请求

内部异常2:WebException:请求被中止:无法 创建SSL/TLS安全通道

我解决不了这个问题

更新: 我在Windows10上测试,它工作得很好,但在我的Windows8.1上不工作。Windows 8.1需要安装什么?

有两件事-

  • 在.NET Core中,ServicePointManager只影响HttpWebRequest。在.NET Framework中,内置HttpClient构建在HttpWebRequest之上,因此ServicePointManager设置将应用于它

    所以在HttpClientHandler中设置要传递到HttpClient构造函数的安全协议

  • 验证机器上是否禁用了所需的TLS版本。既然你说它在一个地方可以正常工作,但在另一个地方却失败了,而且TLS1.2是Windows 8.1上启用的默认协议,那么情况可能就是这样。所以这里是你如何做到的-


  • 您是否尝试过
    ServicePointManager.Expect100Continue=true;ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3?如果注释掉ServicePointManager行会发生什么?在.NETCore中,通常不需要显式设置它。@Selim Yıldız是的,相同problem@Crowcoder.Net核心错误:消息=发生了一个或多个错误。(无法建立SSL连接,请参阅内部异常。)我假设您可以在浏览器中转到该页面?