Skip to main content
4 of 4
added 101 characters in body
Lee Ames
  • 349
  • 1
  • 3
  • 14

API Get requires Content-Type application/json;charset=UTF-8 - Issue with Http Client

I am working with an API service that requires Content-Type to be set to application/json;charset=UTF-8.

If I make a request without the charset=UTF-8 I get a 406 - Not Acceptable.

I can make a call through Postman setting the Content-Type as required, but if I use my .Net Http Client I get the error:

System.FormatException: 'The format of value 'application/json;charset=UTF-8' is invalid.'

Is there anyway I can work around this validation and force the Http Client to accept the value?

UPDATE:

Here is my latest attempt,it still throws the error.

Body.Headers.ContentType = new MediaTypeHeaderValue("application/json;charset=UTF-8");

UPDATE: Content-Type is indeed an invalid header. The API Developers removed it at our request.

Lee Ames
  • 349
  • 1
  • 3
  • 14