C# 获取请求错误“;无法创建SSL/TLS安全通道“;
我尝试从ConsoleApp请求站点页面: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
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.Task1.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需要安装什么?有两件事-
您是否尝试过
ServicePointManager.Expect100Continue=true;ServicePointManager.SecurityProtocol=SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3代码>?如果注释掉ServicePointManager行会发生什么?在.NETCore中,通常不需要显式设置它。@Selim Yıldız是的,相同problem@Crowcoder.Net核心错误:消息=发生了一个或多个错误。(无法建立SSL连接,请参阅内部异常。)我假设您可以在浏览器中转到该页面?