I have been trying to connect to DHL interface but i cannot get the token access key from C# code. here is my current code. Please let me know if you have a solution -
RestClient client = new RestClient();
client.ClearHandlers();
client.Timeout = -1;
client.BaseUrl = new Uri("https://api-sandbox.dhlecs.com/auth/v4/accesstoken");
client.Authenticator = new HttpBasicAuthenticator(ConfigurationManager.AppSettings["DHLClientId"], ConfigurationManager.AppSettings["DHLClientSecret"]);
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
request.AddHeader("Accept", "application/json");
request.Parameters.Clear();
request.AddParameter("grant_type", "client_credentials");
IRestResponse response = client.Execute(request);
var local = response.Content.ToString();
if (response.StatusCode == HttpStatusCode.OK)
{
return response.Content.ToString();
}
else
{
throw new Exception($@"Unable to authorize with GLS. Contact IT");
}
here is the error i get -
>> Solution : this needs to be removed -
request.Parameters.Clear();