You're looking at the
request, not the response.
The request which succeeds is sending the parameters encoded as
application/x-www-form-urlencoded
. The request that fails is sending the parameters encoded as JSON.
You need to add the parameters to the
RestRequest
object instead of using
AddJsonBody
:
RestClient client = new RestClient("http://example.com/connect/token");
RestRequest request = new RestRequest() { Method = Method.POST };
request.AddParameter("grant_type", "password", ParameterType.GetOrPost);
request.AddParameter("username", "client@company.com", ParameterType.GetOrPost);
request.AddParameter("password", "pass", ParameterType.GetOrPost);
request.AddParameter("scope", "scope1", ParameterType.GetOrPost);
request.AddParameter("client_id", "api", ParameterType.GetOrPost);
request.AddParameter("client_secret", "rest", ParameterType.GetOrPost);
IRestResponse token = client.Execute(request);
Request Parameters | RestSharp[
^]
c# - RestSharp post request - Body with x-www-form-urlencoded values - Stack Overflow[
^]