I am using C#, RestSharp to get the bearer token for a sap exposed RestAPI. Here is my code snippet
var client = new RestClient("https://url/oauth2/token");
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddHeader("Authorization", "Basic clientusername:clientpassword");
request.AddParameter("application/x-www-form-urlencoded", "grant_type=password&username=user&password=pwd", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
But no luck - always get below error
{"fault":{"faultstring":"UrlDecoding of the form parameters from the request message failed. The form parameters needs to be url encoded","detail":{"errorcode":"steps.oauth.v2.InvalidRequest"}}}
I used the psotman with same credentials and it worked fine!! Any idea?