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












0















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










share|improve this question























  • ServicePointManager.ServerCertificateValidationCallback is not even necesary for this site. Setting the ServicePointManager.SecurityProtocol, as the answer proposes, is instead mandatory. I would use a real UserAgent header in any case.

    – Jimi
    Nov 20 '18 at 13:58


















0















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










share|improve this question























  • ServicePointManager.ServerCertificateValidationCallback is not even necesary for this site. Setting the ServicePointManager.SecurityProtocol, as the answer proposes, is instead mandatory. I would use a real UserAgent header in any case.

    – Jimi
    Nov 20 '18 at 13:58
















0












0








0








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










share|improve this question














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







vb.net api ssl ssl-certificate






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 12:31









MartaMarta

52




52













  • ServicePointManager.ServerCertificateValidationCallback is not even necesary for this site. Setting the ServicePointManager.SecurityProtocol, as the answer proposes, is instead mandatory. I would use a real UserAgent header in any case.

    – Jimi
    Nov 20 '18 at 13:58





















  • ServicePointManager.ServerCertificateValidationCallback is not even necesary for this site. Setting the ServicePointManager.SecurityProtocol, as the answer proposes, is instead mandatory. I would use a real UserAgent header in any case.

    – Jimi
    Nov 20 '18 at 13:58



















ServicePointManager.ServerCertificateValidationCallback is not even necesary for this site. Setting the ServicePointManager.SecurityProtocol, as the answer proposes, is instead mandatory. I would use a real UserAgent header in any case.

– Jimi
Nov 20 '18 at 13:58







ServicePointManager.ServerCertificateValidationCallback is not even necesary for this site. Setting the ServicePointManager.SecurityProtocol, as the answer proposes, is instead mandatory. I would use a real UserAgent header in any case.

– Jimi
Nov 20 '18 at 13:58














1 Answer
1






active

oldest

votes


















0














Add this before your request:



ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393056%2fretrieve-api-json-https-with-vb-net-error-canceled-the-request-unable-to-cr%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Add this before your request:



    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12





    share|improve this answer




























      0














      Add this before your request:



      ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12





      share|improve this answer


























        0












        0








        0







        Add this before your request:



        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12





        share|improve this answer













        Add this before your request:



        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 '18 at 13:25









        CruleDCruleD

        515138




        515138






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53393056%2fretrieve-api-json-https-with-vb-net-error-canceled-the-request-unable-to-cr%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

            SQL update select statement

            'app-layout' is not a known element: how to share Component with different Modules