1

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

2 Answers 2

1

Try with:

request.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);

It seems is case sensitive now?

Sign up to request clarification or add additional context in comments.

1 Comment

application/x-www-form-urlencoded content type is used by default when making post request with regular parameters. There's a very limited number of cases when you need to set the content type header manually with RestSharp.
1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.