简体   繁体   English

VB。 NET:请求被中止:无法创建 SSL/TLS 安全通道

[英]VB. NET: The request was aborted: Could not create SSL/TLS secure channel

I have an application coded in VB.net that has this method of accessing Webservice, i have this error and after searching fixes i still have no luck.我有一个在 VB.net 中编码的应用程序,它具有这种访问 Web 服务的方法,我有这个错误,在搜索修复后我仍然没有运气。

Error: The request was aborted: Could not create SSL/TLS secure channel.错误:请求被中止:无法创建 SSL/TLS 安全通道。

    'ServicePointManager.Expect100Continue = False
    'ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls

    Dim request As HttpWebRequest = DirectCast(WebRequest.Create(url), HttpWebRequest)

    Dim ErrMsg As String = String.Empty

    Try

        Dim response As WebResponse = request.GetResponse()

        Using responseStream As Stream = response.GetResponseStream()
            Dim reader As New StreamReader(responseStream, Encoding.UTF8)

            Return reader.ReadToEnd()
        End Using
    Catch ex As WebException

        ErrMsg = ex.Message.ToString
        MsgBox(ErrMsg)

        Dim errorResponse As WebResponse = ex.Response
        Using responseStream As Stream = errorResponse.GetResponseStream()
            Dim reader As New StreamReader(responseStream, Encoding.GetEncoding("utf-8"))
            ' log errorText
            Dim errorText As [String] = reader.ReadToEnd()
        End Using
        Throw
    End Try

This is my code and I'm using VS2015 and Windows 10.这是我的代码,我使用的是 VS2015 和 Windows 10。

All help are really appreciated.非常感谢所有帮助。 TIA TIA

Obviously the URL you're calling requires TLS 1.1 or TLS 1.2 .显然,您调用的 URL 需要TLS 1.1TLS 1.2

You can enable TLS 1.1 or TLS 1.2 by setting the security-protocol with ServicePointManager.SecurityProtocol :您可以通过使用ServicePointManager.SecurityProtocol设置安全协议来启用TLS 1.1TLS 1.2

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

.NET 4.0 supports up to TLS 1.0 while .NET 4.5 or higher supports up to TLS 1.2 .NET 4.0最高支持TLS 1.0.NET 4.5或更高版本最高支持TLS 1.2
For reference:供参考:

I'm going to add something here in case it helps others.我将在这里添加一些东西,以防它对其他人有帮助。 I have to support some legacy code that is written in VB.Net and targets .NET Framework 4.6.1.我必须支持一些用 VB.Net 编写并针对 .NET Framework 4.6.1 的遗留代码。 The same piece of code runs in both an .exe, and in IIS as a web page.同一段代码在 .exe 和 IIS 中作为网页运行。

In the website, this call:在网站上,这个电话:

Dim dataStream As Stream = request.GetRequestStream()

would throw this exception会抛出这个异常

The request was aborted: Could not create SSL/TLS secure channel.

but it worked fine in the .exe.但它在 .exe 中运行良好。

Forcing the TLS protocol fixed it in the website.强制使用 TLS 协议在网站上修复了它。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

Of course if the host ever deems TLS 1.2 unworthy I'll have to fix/recompile/redeploy, but it solved the error for now.当然,如果主机认为 TLS 1.2 不值得,我将不得不修复/重新编译/重新部署,但它现在解决了错误。

for vb.net 4.0 this worked for me: ServicePointManager.SecurityProtocol = DirectCast(&HC0 Or &H300 Or &HC00, SecurityProtocolType)对于 vb.net 4.0 这对我有用:ServicePointManager.SecurityProtocol = DirectCast(&HC0 Or &H300 Or &HC00, SecurityProtocolType)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VB。 NET:请求被中止:无法在 WebClient 上创建 SSL/TLS 安全通道 - VB. NET: The request was aborted: Could not create SSL/TLS secure channel on WebClient SOAP错误:请求已中止:无法创建SSL / TLS安全通道 - SOAP Error: The request was aborted: Could not create SSL/TLS secure channel ASP.NET“请求被中止:无法创建 SSL/TLS 安全通道”也出现在配置的 servicepointmanager 中 - ASP.NET "The request was aborted: Could not create SSL/TLS secure channel" occurs also with configured servicepointmanager 该请求已中止:使用X509Certificate2时无法创建SSL / TLS安全通道 - The request was aborted: Could not create SSL/TLS secure channel when using X509Certificate2 VB.NET Web服务无法连接:“无法创建SSL / TLS安全通道” - VB.NET Web Service connection impossible : “Could not create SSL/TLS secure channel” vb无法为SSL / TLS建立安全通道 - vb Could not establish secure channel for SSL/TLS 使用VB.NET检索API JSON(https)(错误:取消了请求:无法创建安全的SSL / TLS通道) - Retrieve API JSON (https) with VB.NET (ERROR: Canceled the request: Unable to create a secure SSL / TLS channel) XmlReader.Create错误“无法创建SSL / TLS安全通道” - XmlReader.Create error “Could not create SSL/TLS secure channel” IIS 阻止我的请求。 无法创建 SSL/TLS 安全通道 - IIS Blocking My Request. Could not create SSL/TLS secure channel 我如何修复 ASP.NET 中的无法创建 SSL/TLS 安全通道错误 - How do i fix the Could not create SSL/TLS secure channel Error in ASP.NET
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM