C# 某些站点上的HTTPs请求和SslStream存在问题

C# 某些站点上的HTTPs请求和SslStream存在问题,c#,ssl,sslstream,tls1.3,C#,Ssl,Sslstream,Tls1.3,我有一个简单的C应用程序,它使用TcpClient和SslStream发出HTTPs请求。一切正常,除了一些使用TLS1.3的网站失败。我将项目升级到.NETFramework4.8,阅读速度也很慢,但我无法找到解决方案 我使用的是Windows 10 64位编译19041.508 下面是我能提供的最简单的代码示例: using System; using System.Text; using System.Windows.Forms; using System.IO; using System

我有一个简单的C应用程序,它使用
TcpClient
SslStream
发出HTTPs请求。一切正常,除了一些使用TLS1.3的网站失败。我将项目升级到.NETFramework4.8,阅读速度也很慢,但我无法找到解决方案

我使用的是Windows 10 64位编译19041.508

下面是我能提供的最简单的代码示例:

using System;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
如果您尝试使用hostname
stackoverflow.com
它会工作,但如果您使用例如
manga001.com
它会失败并引发异常。例外情况详情:

System.Security.Authentication.AuthenticationException
  HResult=0x80131501
  Mensaje = A call to SSPI failed, see inner exception.
  Origen = System
  Seguimiento de la pila:
   en System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, Exception exception)
   en System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   en System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   en System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest)
   en System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest)
   en System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest)
   en System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   en System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest)
   en System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest)
   en System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult)
   en System.Net.Security.SslStream.AuthenticateAsClient(String targetHost, X509CertificateCollection clientCertificates, SslProtocols enabledSslProtocols, Boolean checkCertificateRevocation)
   en http_minimal.Form1.button1_Click(Object sender, EventArgs e) en C:\Users\VA\source\repos\http_minimal\http_minimal\Form1.cs: línea 36
   en System.Windows.Forms.Control.OnClick(EventArgs e)
   en System.Windows.Forms.Button.OnClick(EventArgs e)
   en System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   en System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   en System.Windows.Forms.Control.WndProc(Message& m)
   en System.Windows.Forms.ButtonBase.WndProc(Message& m)
   en System.Windows.Forms.Button.WndProc(Message& m)
   en System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   en System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   en System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   en System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   en System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
   en System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   en System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   en System.Windows.Forms.Application.Run(Form mainForm)
   en http_minimal.Program.Main() en C:\Users\VA\source\repos\http_minimal\http_minimal\Program.cs: línea 19

Excepción interna 1:
Win32Exception: No se permite la función solicitada

希望有人能帮我解决这个问题,我花了很多时间却找不到解决方案。

请尝试:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
请尝试:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;

在一项令人沮丧的研究之后,我将对此给予一些启示。目前的Windows 10版本似乎不完全支持TLS 1.3。微软宣布了一个更新


换句话说,我们必须等到Microsoft启动该更新后才能检查问题是否仍然存在。目前这个问题无法解决,因为Windows 10 v19042.685(20H2)无法支持测试网页所需的TLS 1.3密码。

经过令人沮丧的研究后,我想解释一下这一点。目前的Windows 10版本似乎不完全支持TLS 1.3。微软宣布了一个更新


换句话说,我们必须等到Microsoft启动该更新后才能检查问题是否仍然存在。目前无法修复此问题,因为Windows 10 v19042.685(20H2)无法支持测试网页所需的TLS 1.3密码。

您能在此处发布整个异常吗?添加了完整的异常文本。谢谢。这不是客户端问题,因为它与某些服务器而不是其他服务器一起工作。服务器是问题所在。确保服务器安装了相同的证书,并确保服务器具有相同的Net版本。服务器使用的是什么应用程序?你们是如何安装应用程序的?我不是服务器的所有者,服务器本身在互联网上运行,所以我不需要在服务器上安装任何东西。我建议您慢慢阅读代码并描述问题。所有经过测试的webapges在FireFox、Chrome等浏览器中都能完美运行。。。仅当我尝试使用SSLStream代码访问时失败。您能在此处发布整个异常吗?添加了完整的异常文本。谢谢。这不是客户端问题,因为它与某些服务器而不是其他服务器一起工作。服务器是问题所在。确保服务器安装了相同的证书,并确保服务器具有相同的Net版本。服务器使用的是什么应用程序?你们是如何安装应用程序的?我不是服务器的所有者,服务器本身在互联网上运行,所以我不需要在服务器上安装任何东西。我建议您慢慢阅读代码并描述问题。所有经过测试的webapges在FireFox、Chrome等浏览器中都能完美运行。。。仅当我尝试使用SSLStream代码访问时失败。我应该在哪里使用它?我使用对SSL流进行了测试,并抛出了相同的错误。您能更详细地介绍您的解决方案吗?我在启动时使用它,我使用HttpWebRequest。尝试查找这样的代码:var request=(HttpWebRequest)WebRequest.Create(Address);如果您慢慢检查我的代码,我不是在使用HttpWebRequest,而是在使用tcpclient和sslstream。我应该在哪里使用它?我使用对SSL流进行了测试,并抛出了相同的错误。您能更详细地介绍您的解决方案吗?我在启动时使用它,我使用HttpWebRequest。尝试查找这样的代码:var request=(HttpWebRequest)WebRequest.Create(Address);如果您慢慢检查我的代码,我不是在使用HttpWebRequest,而是在使用tcpclient和sslstream。