0

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;
  }
Nlr
  • 183
  • 3
  • 13
  • 1
    In what Windows (?) System is this code run? – Jimi Nov 10 '20 at 09:32
  • This runs on windows 10 – Nlr Nov 10 '20 at 14:12
  • 1
    Windows 10 defaults to TLS 1.2. Are you sure that the EndPoint you're calling supports this protocol? Which is the minimum SSL protocol version supported by that EndPoint? Or, do you have Proxies in between? – Jimi Nov 10 '20 at 14:23
  • 1
    @Jimi thank you very much for the input. I went along the path you suggested and managed to found the issue. this endpoint is behind a WAF and the people who has configured WAF attached an old TLS profile for the host name (by mistake). I think the .net core httpclient does not support that version of TLS they had there. WAF now have the latest TLS and it works fine. btw fyi, IE and Edge also had the same issue but not chrome may be they support old TLS. Thanks again. – Nlr Nov 12 '20 at 09:06

1 Answers1

0

I had the same issue calling a web service. I was able to fix it by updating "Load User Profile" to true on the IIS AppPool advanced properties.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77