RestSharp: Error when refreshing token

Hello Team!

A newbie here, trying to refresh token using RestSharp. We are trying to set-up a console app that runs periodically (before access_token expires). However we got the following errors when trying to run the app:

ErrorMessage: The underlying connection was closed: An unexpected error occurred on a send.

InnerException: Authentication failed because the remote party has closed the transport stream.

code snippet as follows:

       //---- START ---

        string refresh_token = "abc123";

        var client = new RestClient("https://api.infusionsoft.com/token");
        var request = new RestRequest(Method.POST);

        request.AddHeader("content-type", "application/x-www-form-urlencoded");
        
        request.AddParameter("grant_type", "refresh_token");
        request.AddParameter("refresh_token", refresh_token);
        request.AddParameter("Authorization", string.Format("Basic {0}", Base64Encode(client_id + ":" + client_secret)));

        IRestResponse response = client.Execute(request);

       ...

    string Base64Encode(string plainText)
    {
        var plainTextBytes = Encoding.ASCII.GetBytes(plainText);
        return Convert.ToBase64String(plainTextBytes);
    }

   //---- END ---

changing the encoding to UTF8 yields same results.

was tryin to check for similar topics involving RestSharp, to no success. appreciate any help from the Pros.

I’m not an expert on C# but I’ve seen other posts where some have used HttpClient…I honestly don’t know how much difference that makes but they did end up with a working solution each time?