Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net VB。NET:请求被中止:无法创建SSL/TLS安全通道_Vb.net - Fatal编程技术网

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

Vb.net VB。NET:请求被中止:无法创建SSL/TLS安全通道,vb.net,Vb.net,我有一个用VB.net编写的应用程序,它有这种访问Web服务的方法,我有这个错误,在搜索修复后,我仍然没有运气 错误: 请求被中止:无法创建SSL/TLS安全通道 'ServicePointManager.Expect100Continue = False 'ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls Dim request As HttpWebRequest = DirectCast(

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

错误: 请求被中止:无法创建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
这是我的代码,我正在使用VS2015和Windows 10


非常感谢您的帮助。TIA

显然,您调用的URL需要
TLS1.1
TLS1.2

通过使用
ServicePointManager设置安全协议,可以启用
TLS 1.1
TLS 1.2
。SecurityProtocol

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
.NET 4.0
最多支持
TLS 1.0
,而
.NET 4.5
或更高版本 最多支持
TLS 1.2

以供参考:


我将在这里添加一些东西,以防对其他人有所帮助。我必须支持一些用VB.Net和targets.NETFramework 4.6.1编写的遗留代码。同一段代码作为网页在.exe和IIS中运行

在网站中,此呼叫:

Dim dataStream As Stream = request.GetRequestStream()
将抛出此异常

The request was aborted: Could not create SSL/TLS secure channel.
但它在.exe中运行良好

强制TLS协议在网站中修复了它

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

当然,如果主机曾经认为TLS 1.2不值得,我将不得不修复/重新编译/重新部署,但它现在解决了错误。

也许Web服务需要TLS 1.1/1.2?是的,Mat我想这里的问题就在这段代码中:ServicePointManager.SecurityProtocol=SecurityProtocolType.TlsThanks Mat,我尝试了这个解决方案,是的,它是有效的,我创建了一个以4.5框架为目标的新项目,现在的挑战是,我的项目以4.0框架为目标,当我将其更改为4.5时,出现了一系列错误。对于公共门户,我必须检查存储的URL是否仍然适用于System.Net.WebRequest。因此,我注意到,当站点同时更新为https时,http调用会崩溃(浏览器会自动处理此问题)。有了你的答案,它现在可以工作了。谢谢,它成功了。我必须将项目属性中的目标框架(右键单击解决方案资源管理器上的项目->属性->应用程序)更改为4.6.1才能使用它