簡體   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