gpt4 book ai didi

vb.net - SSL TLS 1.2 channel 创建 VB.net HTTPS WebRequest

转载 作者:太空宇宙 更新时间:2023-11-03 13:11:32 24 4
gpt4 key购买 nike

我有一个遗留的 Visual Studio 2010 vb.net 应用程序,我需要更新 SSL TLS channel 以支持 TLS 1.2。我尝试了几个不同的选项(请参阅尝试的注释代码),但都导致我遇到相同的错误,“无法创建 SSL/TLS 安全通道。”我错过了什么?

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 3.5,请使用此脚本

ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType)

关于vb.net - SSL TLS 1.2 channel 创建 VB.net HTTPS WebRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42817334/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com