I have a request (going to an APIM endpoint.) From Postman the test runs just fine, but from my code it fails with a 400. I looked at the requests in fiddler and the only difference is this:
// This works
Content-Type: application/json
// This gives a 400
Content-Type: application/json; charset=utf-8
APIM is supposed to use UTF-8 by default, so I don't understand. Plus there doesn't seem to be a way within the C# code to produce the first. If I try to add the header directly it complains that I need to add it as part of the content string. So I have this:
requestMessage.Content = new StringContent(content, Encoding.UTF8, "application/json");
This produces the second Content-Type header. There seems to be no overload on the StringContent class to allow me to produce the first version (without specifying the encoding.)
I'm stuck. It seems a really simply problem but I don't see a way to get through all the "helper" code that Microsoft has put in place to get what I need.
Insofar as it matters I am running .net8.
Any suggestions?
content.Headers.ContentType.CharSet = nullAPIM? What you describe sounds like a service bug. Also, why are you serializing manually instead of using egPostAsJsonAsync? Or use JsonContent ? JsonContent.Create allows you to set your ownMediaTypeHeaderValueI am not serializing manuallyif you generate a string from your DTO and send it as aStringContent, you are. You can just post your DTO so why don't you? Was there a problem?