0
我有一個遺留的Visual Studio 2010 vb.net應用程序,我需要更新SSL TLS通道以支持TLS 1.2。我嘗試了幾個不同的選項(請參閱評論代碼嘗試),並且所有這些都導致我出現相同的錯誤,「無法創建SSL/TLS安全通道」。我錯過了什麼?SSL TLS 1.2通道創建VB.net HTTPS WebRequest
Public Shared Function processCCRequest(ByVal strRequest As String) As String
'declare the web request object and set its path to the PayTrace API
Dim ThisRequest As WebRequest = WebRequest.Create("https://beta.paytrace.com/api/default.pay")
'configure web request object attributes
ThisRequest.ContentType = "application/x-www-form-urlencoded"
ThisRequest.Method = "POST"
'encode the request
Dim Encoder As New System.Text.ASCIIEncoding
Dim BytesToSend As Byte() = Encoder.GetBytes(strRequest)
'declare the text stream and send the request to PayTrace's API
Dim StreamToSend As Stream = ThisRequest.GetRequestStream
StreamToSend.Write(BytesToSend, 0, BytesToSend.Length)
StreamToSend.Close()
''ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
''allows for validation of SSL conversations
''ServicePointManager.ServerCertificateValidationCallback = New System.Net.Security.RemoteCertificateValidationCallback(AddressOf)
ServicePointManager.Expect100Continue = True
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
''| SecurityProtocolType.Tls11 | SecurityProtocolType.Tls
''var(response = WebRequest.Create("https://www.howsmyssl.com/").GetResponse())
''var(body = New StreamReader(response.GetResponseStream()).ReadToEnd())
'Catch the response from the webrequest object
Dim TheirResponse As HttpWebResponse = ThisRequest.GetResponse
Dim sr As New StreamReader(TheirResponse.GetResponseStream)
Dim strResponse As String = sr.ReadToEnd
'Out put the string to a message box - application should parse the request instead
' MsgBox(strResponse)
sr.Close()
Return strResponse
End Function
非常感謝您的建議!
我認爲.NET 4.5中增加了TLS 1.2支持,所以你需要安裝它,然後在4.0代碼中使用'ServicePointManager.SecurityProtocol = DirectCast(3072,SecurityProtocolType)'解決方法。 – Mark
是的,在我的回答中,我根據這些信息進一步完成了我的任務。 –