I have a .net core console app with a function that will do a simple http call and get the page content (this is for a testing). I am getting an issue "The SSL connection could not be established". But when I try the same url with Postman or a browser it works fine. Can anyone help me on this?
inner exception:"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.."
private static async Task<string> CallUrl(string url)
{
using var client = new HttpClient();
using var response = await client.GetAsync(url);
using var content = response.Content;
var data = await content.ReadAsStringAsync();
return data;
}
I tried the suggestion in The SSL connection could not be established as well. like this but no luck.
private static async Task<string> CallUrl(string url)
{
var clientHandler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) =>
{
return true;
}
};
using var client = new HttpClient(clientHandler);
using var response = await client.GetAsync(url);
using var content = response.Content;
var data = await content.ReadAsStringAsync();
return data;
}