简体   繁体   中英

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

I'm trying to query an API from my vb.net code but at the time of executing the "GetResponse" it gives the error " Canceled the request: Unable to create a secure SSL / TLS channel "

I have modified many things of the code tried to solve my problem but nothing works ...

I attach the code that I have to see if someone can fix it

    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

In the code you have the address of the api tal as I want to consult it

在您的请求之前添加此:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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