C#学习教程:无法使用WebClient.DownloadFile方法从启用TLS1.1/1.2协议的计算机下载文件我正在尝试使用Webclient。DownloadFile方法实现一个简单的控制台应用程序以通过TLS1.1/1.2协议下载文件。这是应用程序的代码:vardownloadUrl="https://serverURL.com/sample.mp3";var文件名="sample.mp3";varmyWebClient=newWebClient();myWebClient.DownloadFile(downloadUrl,文件名);每次运行它我都会收到以下错误消息:未处理的异常:System.Net.WebException:底层连接已关闭:接收时发生意外错误。--->System.ComponentModel.Win32Exception:客户端和服务器无法通信,因为它们在System.Net.SSPIWrapper.AcquireCredentialsHandle(SSPIInterfaceSecModule,Stringpackage,CredentialUseintent,SecureCredentialscc)处不具备通用算法Security.SecureChannel.AcquireCredentialsHandle(CredentialUsecredUsage,SecureCredential&secureCredential)在System.Net.Security.SecureChannel.AcquireClientCredentials(Byte[]&thumbPrint)在System.Net.Security.SecureChannel.GenerateToken(Byte[]输入,Int32偏移量,Int32计数,Byte[]&输出)在System.Net.Security.SecureChannel.NextMessage(Byte[]传入,Int32偏移量,Int32计数)在System.Net.Security.SslState.StartSendBlob(Byte[]传入,Int32计数,AsyncProtocolRequestasyncRequest)在System.Net.Security.SslState.ForceAuthentication(BooleanreceiveFirst,Byte[]缓冲区,AsyncProtocolRequestasyncRequest)在System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResultlazyResult)在System.Net.TlsStream.CallProcessAuthentication(对象状态)在System.Threading.ExecutionContext.RunInternal(ExecutionContextexecutionContext,ContextCallback回调,对象状态,BooleanpreserveSyncCtx)在System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallbackcallback,Objectstate,BooleanpreserveSyncCtx)在System.Threading.ExecutionContext.Run(ExecutionContextexecutionContext,ContextCallbackcallback,Objectstate)在System.Net.TlsStream。ProcessAuthentication(LazyAsyncResult结果)在System.Net.TlsStream.Write(字节[]缓冲区,Int32offset,Int32size)atSystem.Net.PooledStream.Write(Byte[]buffer,Int32offset,Int32size)atSystem.Net.ConnectStream.WriteHeaders(Booleanasync)---内部异常堆栈跟踪结束---在System.Net.WebClient.DownloadFile(Uri地址,字符串文件名)在System.Net.WebClient.DownloadFile(字符串地址,字符串文件名)在web_downloader.Program.Main(String[]args)在c:UsersuserDocumentsVisualStudio2013Projectsweb_downloaderweb_downloaderProgram.cs:line27我有以下设置:web_downloader应用程序位于ServerA(WindowsServer2012R2/64位)上,它在HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Control/SecurityProviders/SCHANNEL/Protocols下的注册表项中具有以下内容:PCT1.0--Client----DisabledByDefault=1----Enabled=0--Server----DisabledByDefault=1----Enabled=0SSL2.0--Client----DisabledByDefault=1----Enabled=0--Server----DisabledByDefault=1----Enabled=0SSL3.0--Client----DisabledByDefault=1----Enabled=0--Server----DisabledByDefault=1----Enenabled=0TLS1.0--Client----DisabledByDefault=1----Enabled=0--Server----DisabledByDefault=1----Enabled=0TLS1.1--Client----DisabledByDefault=0----Enabled=1--Server----DisabledByDefault=0----Enabled=1TLS1.2--Client----DisabledByDefault=0----Enabled=1--Server----DisabledByDefault=0----Enabled=1存储sample.mp3文件的ServerB具有以下内容:SSL2.0ClientDisabledByDefault=1TLS1.1ClientDisabledByDefault=0Enabled=1ServerDisabledByDefault=0Enabled=1TLS1.2ClientDisabledByDefault=0Enabled=1ServerDisabledByDefault=0Enabled=1一旦我在ServerA上启用了TLS1.0,我就能够从ServerB(Windows7/64位/NetFramework4.5.1)下载mp3文件而没有任何问题系统加密:在两者上禁用使用每台计算机上用于加密、散列和签名策略的FIPS兼容算法。我是否缺少DownloadFile方法使用TLS1.1/1.2的任何配置参数?.NETFramework使用自己的设置来确定默认使用哪个HTTPS版本。请参阅https://stackoverflow.com/a/169396/126229以了解要在客户端上设置的ServicePointManager.SecurityProtocol设置,以确保它尝试协商TLS1.1连接。您还可以使用Fiddler(查看CONNECT隧道的TextView请求检查器)查看出站流量以查看ClientHello消息的细分。请注意,在启用HTTPS解密的情况下运行Fiddler会产生干扰,因为Fiddler本身默认使用SSL3+TLS1与服务器通信。如果您使用的是.NETFramwork3.5或更低版本,则只能设置TLS1.0(输入注册表项),并且必须在服务器上启用TLS1.0。以上为C#学习教程:WebClient.DownloadFile方法无法从启用TLS1.1/1.2协议的电脑上下载文件共享的全部内容。如果对大家有用,需要进一步了解C#学习教程,希望大家多多关注——本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
