VB。NET:请求被中止:无法创建 SSL/TLS 安全通道
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46825387/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VB. NET: The request was aborted: Could not create SSL/TLS secure channel
提问by wysiwyg327
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
回答by MatSnow
Obviously the URL you're calling requires TLS 1.1or TLS 1.2.
显然,您正在调用的 URL 需要TLS 1.1或TLS 1.2。
You can enable TLS 1.1or TLS 1.2by setting the security-protocol with ServicePointManager.SecurityProtocol:
您可以启用TLS 1.1或TLS 1.2通过设置安全协议ServicePointManager.SecurityProtocol:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
.NET 4.0supports up toTLS 1.0while.NET 4.5or higher supports up toTLS 1.2
For reference:
.NET 4.0支持高达TLS 1.0while.NET 4.5或更高 支持高达TLS 1.2
参考:

