When trying to send some JSON data through an HTTP POST, I got the following exception message back:
The request entity's media type 'text/plain' is not supported for this resource. No MediaTypeFormatter is available to read an object of type 'TransportDocument' from content with media type 'text/plain'
This error showed up because I forgot to specify the content type in the HTTP headers. Here is one way how to fix this:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var json = JsonConvert.SerializeObject(body); | |
var content = new StringContent(json); | |
content.Headers.ContentType= new MediaTypeHeaderValue("application/json"); | |
return _client.PostAsync(requestUri, content); |