0

httpClient.DefaultRequestHeaders.Add("Accept", "application/vnd.pagseguro.com.br.v3+json;charset=ISO-8859-1");

Is there any bug related to how you should add a accept header to a request?

This is a request for a specific payment gateway in Brazil (pagseguro). I've already posted in their forums but none of the members seems to be using .NET Core there yet.

Message I get: Accept header is mandatory

1 Answers1

0

You should try something like:

httpClient.DefaultRequestHeaders.Accept.Clear();

httpClient.DefaultRequestHeaders.Accept.Add(
    new MediaTypeWithQualityHeaderValue("application/vnd.pagseguro.com.br.v3+json"));

httpClient.DefaultRequestHeaders.Accept.Add(
    new MediaTypeWithQualityHeaderValue("charset=ISO-8859-1"));

DefaultRequestHeaders.Accept is a collection of string type, where you can add your header to accept using the new instance of MediaTypeWithQualityHeaderValue.

Hackerman
  • 12,139
  • 2
  • 34
  • 45
  • httpClient.DefaultRequestHeaders.Accept.Clear(); The line above seemed to resolve. The two following ones were not valid accept headers according to c# compiler, so I kept the previous one: httpClient.DefaultRequestHeaders.Add("Accept", "application/vnd.pagseguro.com.br.v3+json;charset=ISO-8859-1"); – Vinícius Filenga Feb 11 '18 at 16:26