我有一个用 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.1
或 TLS 1.2
.
您可以启用 TLS 1.1
或 TLS 1.2
通过使用 ServicePointManager.SecurityProtocol
设置安全协议(protocol):
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
.NET 4.0
supports up toTLS 1.0
while.NET 4.5
or higher supports up toTLS 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/