Closed abdeldjalil-fellah closed 3 years ago
That should be working. Using this sample:
public class Program
{
static void Main()
{
var httpClient = new HttpClient(new HttpClientHandler { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator });
httpClient.BaseAddress = new Uri("https://en62ab5snoazt.x.pipedream.net");
var api = RestClient.For<IApiPrivilege>(httpClient);
api.ShuffleSync("test").Wait();
}
[Header("Content-Type", "application/json; charset=UTF-8")]
public interface IApiPrivilege
{
[Get("/shuffle")]
Task ShuffleSync([Body] string foo);
}
}
Produces this request, and you can see the Content-Type header there.
I don't believe HttpClient has a way for you to set a default content header.
after debugging actually the error was thrown when model == null, so it has nothing with RestEase! and there is no need to add the [Header] attribute, I think RestEase added it automatically if any [Body] attribute is detected.
Content-related headers only get applied when there's actually a content -- if the body is null, Content-Type won't be sent.
This has been changed in version 1.5.1 -- if a [Body]
parameter is declared on the method, then content-related headers are always sent.
requests sent to the server do not contain the "Content-Type" header! hence api.ShuffleSync(model, query) generates 415 status code how to add that header globally to the httpClient instead of adding it to each interface?