Reputation: 68750
In a previous version of RestSharp I was able to add a content-type:application/json
RestClientOptions options = new RestClientOptions();
options.BaseUrl = new Uri($"https://{_options.Auth0Domain}");
var client = new RestClient(options);
var request = new RestRequest("/oauth/token") { Method = Method.Post };
request.AddHeader("content-type", "application/json");
request.AddParameter("application/json", json, ParameterType.RequestBody);
var response = await client.ExecuteAsync<Auth0MachineToMachineResponse>(request);
But after the big 107 release I get this error when I try to add the content-type, which is required by the end point I am calling:
"Misused header name, 'content-type'. Make sure request headers are used with HttpRequestMessage
Upvotes: 1
Views: 4335
Reputation: 19610
Please do not add content type manually.
Use AddStringBody
and the content type for the body parameter instead.
var request = new RestRequest("/oauth/token").AddStringBody(json, "application/json");
var response = await client.PostAsync<Auth0MachineToMachineResponse>(request);
Upvotes: 1
Reputation: 96
Try with:
request.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
It seems is case sensitive now?
Upvotes: 1