Retrieve API JSON (https) with VB.NET (ERROR: Canceled the request: Unable to create a secure SSL / TLS...
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
add a comment |
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
ServicePointManager.ServerCertificateValidationCallback
is not even necesary for this site. Setting theServicePointManager.SecurityProtocol
, as the answer proposes, is instead mandatory. I would use a realUserAgent
header in any case.
– Jimi
Nov 20 '18 at 13:58
add a comment |
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
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
vb.net api ssl ssl-certificate
asked Nov 20 '18 at 12:31
MartaMarta
52
52
ServicePointManager.ServerCertificateValidationCallback
is not even necesary for this site. Setting theServicePointManager.SecurityProtocol
, as the answer proposes, is instead mandatory. I would use a realUserAgent
header in any case.
– Jimi
Nov 20 '18 at 13:58
add a comment |
ServicePointManager.ServerCertificateValidationCallback
is not even necesary for this site. Setting theServicePointManager.SecurityProtocol
, as the answer proposes, is instead mandatory. I would use a realUserAgent
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
add a comment |
1 Answer
1
active
oldest
votes
Add this before your request:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Add this before your request:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
add a comment |
Add this before your request:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
add a comment |
Add this before your request:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
Add this before your request:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
answered Nov 20 '18 at 13:25
CruleDCruleD
515138
515138
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
ServicePointManager.ServerCertificateValidationCallback
is not even necesary for this site. Setting theServicePointManager.SecurityProtocol
, as the answer proposes, is instead mandatory. I would use a realUserAgent
header in any case.– Jimi
Nov 20 '18 at 13:58