Unable to complete a connection

I am having trouble getting started. I have written some code below in C#. I get “The underlying connection was closed: An unexpected error occurred on a send.” which means FreshDesk didn’t like something – but it looks correct according to their documentation. The APIKey is mine and the domain is correct.

What am I doing wrong?

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create($"https://{domain}.freshdesk.com/api/v2/tickets" );
        req.ContentType = "application/json";
        req.Method = "GET";
        req.Timeout = 10000;

        string encoded = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes($"{myapikey}:X"));
        req.Headers.Add("Authorization", $"Basic {encoded}");
        WebResponse w = req.GetResponse();

There is nothing wrong with this code. The issue is site security, Freshdesk uses TLS1.2. I was using .NET Framework 4.5.2 and that defaults to TLS1.1 – therefore it doesn’t work. Two solutions:

  1. Use a later framework. 4.7 certainly works as does .NET Core
  2. Add this line before the request:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

1 Like

Hi @RobChafer,
Welcome to the community ! :wave: Glad you were able to solve this. Thanks for adding the solution. This would definitely be of help to others who might run into the same issue