Reputation: 3014
Im exploring a system of applications i have not built and that doesnt have any documentation. Im trying to make an api request from it that fails. Iver tried two different ways one with Microsofts HttpClient and the other try is with the RestSharp librabry. Both work when i run them outside of the application. From CH Fiddler onlie or a test application that i create just to debug.
What can there be in the application that stops the call and why?
The error i get:
WebException: The request was aborted: Could not create SSL/TLS secure channel.
Method one:
var client = new HttpClient();
var clientResponse = client.GetStringAsync("https://xkcd.com/info.0.json").Result;
var clientJson = JsonConvert.DeserializeObject<dynamic>(clientResponse);
var imgUrl = clientJson.img;
Method two
var restClient = new RestClient();
restClient.BaseUrl = "https://xkcd.com";
var request = new RestRequest();
request.Resource = "/info.0.json";
var response = restClient.Execute<dynamic>(request);
// json["alt"] json["img"] eller json.img
var json = JsonConvert.DeserializeObject<dynamic>(response.Content);
var x = json.img;
The application runs net 4.5.
Upvotes: 1
Views: 1534
Reputation: 235
you can also add this line before you do any request
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
Upvotes: 3