Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.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
SSL TLS 1.2通道创建VB.net HTTPS WebRequest_Vb.net_Ssl_Webrequest - Fatal编程技术网

SSL TLS 1.2通道创建VB.net HTTPS WebRequest

SSL TLS 1.2通道创建VB.net HTTPS WebRequest,vb.net,ssl,webrequest,Vb.net,Ssl,Webrequest,我有一个旧的Visual Studio 2010 vb.net应用程序,需要更新SSL TLS通道以支持TLS 1.2。我尝试了几个不同的选项(请参阅注释代码以获取尝试),但都导致了相同的错误,“无法创建SSL/TLS安全通道”。我缺少什么 Public Shared Function processCCRequest(ByVal strRequest As String) As String 'declare the web request object and set its pat

我有一个旧的Visual Studio 2010 vb.net应用程序,需要更新SSL TLS通道以支持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

提前感谢您的建议

从Microsoft下载并安装.net 4.6目标软件包后,我完全成功了。这添加了完整的.net升级,包括TLS 1.2支持,并添加了.net 4.6作为发布选项。一旦我升级并发布了,上面的代码与设置为TLS 1.2的安全协议一起工作。

如果使用.net 3.5,请使用此脚本

ServicePointManager.SecurityProtocol = DirectCast(3072, SecurityProtocolType)

我认为TLS 1.2支持是在.NET 4.5中添加的,因此您需要安装它,然后使用
ServicePointManager.SecurityProtocol=DirectCast(3072,SecurityProtocolType)
解决4.0代码的问题。是的,在我的回答中,我根据这些信息进一步完成了我的任务。