繁体   English   中英

使用VB.NET检索API JSON(https)(错误:取消了请求:无法创建安全的SSL / TLS通道)

[英]Retrieve API JSON (https) with VB.NET (ERROR: Canceled the request: Unable to create a secure SSL / TLS channel)

我正在尝试从vb.net代码中查询API,但是在执行“ GetResponse”时出现错误“ 已取消请求:无法创建安全的SSL / TLS通道

我已经修改了代码的许多内容,试图解决我的问题,但是没有任何效果...

我附上我必须看的代码,看是否有人可以修复它

    Dim request As HttpWebRequest = HttpWebRequest.Create("https://api.flightstats.com/flex/schedules/rest/v1/json/flight/AA/1917/departing/2018/11/19?appId=583f892b&appKey=e960901ec7dcb40321306743b7a364d0")
    request.Proxy = Nothing
    request.UserAgent = "Test"

    ServicePointManager.ServerCertificateValidationCallback = AddressOf AcceptAllCertifications

    Dim response As HttpWebResponse = request.GetResponse
    Dim response_stream As System.IO.Stream = response.GetResponseStream

    Dim stream_reader As New System.IO.StreamReader(response_stream)
    Dim Data As String = stream_reader.ReadToEnd
    stream_reader.Close()

    MsgBox(Data)

_

Public Function AcceptAllCertifications(ByVal sender As Object, ByVal certification As System.Security.Cryptography.X509Certificates.X509Certificate, ByVal chain As System.Security.Cryptography.X509Certificates.X509Chain, ByVal sslPolicyErrors As System.Net.Security.SslPolicyErrors) As Boolean
    Return True
End Function

在代码中,您具有我想查询的api地址

在您的请求之前添加此:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM