vb.net - VB。净 : The request was aborted: Could not create SSL/TLS secure channel

标签 vb.net

我有一个用 VB.net 编码的应用程序,它有这种访问 Web 服务的方法,我有这个错误,在搜索修复后我仍然没有运气。

错误:
请求被中止:无法创建 SSL/TLS 安全 channel 。

    '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

这是我的代码,我使用的是 VS2015 和 Windows 10。

非常感谢所有帮助。 TIA

最佳答案

显然,您调用的 URL 需要 TLS 1.1TLS 1.2 .

您可以启用 TLS 1.1TLS 1.2通过使用 ServicePointManager.SecurityProtocol 设置安全协议(protocol):

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
For reference:

关于vb.net - VB。净 : The request was aborted: Could not create SSL/TLS secure channel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46825387/

相关文章:

c# - .NET Windows 服务 - 架构决策

vb.net - VB.NET错误-使用结果时,在运行时可能会出现Null引用异常

java - 我在客户端上没有收到来自服务器的消息

c# - 如何在上下文菜单条中设置组合框的默认项目?

.net - 我的整个解决方案是否有变量之类的东西?

c# - 阅读器关闭时调用 Read 的尝试无效。 ExecuteReader获取多表结果

vb.net - 使用什么语言

asp.net - GroupBox 不在工具箱中

javascript - 如何将代码隐藏信息传递到 JavaScript 函数中

.net - 在 .Net MDI 中包含 VB6 表单