I had been struggling with a odd error when performing a POST from a WebApi project.
The server was refusing the request because the request is in a format not supported by that method.
The code causing the error:
1 2 |
var content = new StringContent(json); HttpResponseMessage response = await client.PostAsync("Preview", content); |
Fortunately the StringContent has an overload that allows the formatting to be supplied
1 2 |
var content = new StringContent(json, Encoding.UTF8, "application/json"); HttpResponseMessage response = await client.PostAsync("Preview", content); |
And that fixes this error