I have an ASP.NET Web API endpoint with controller action defined as follows :
[HttpPost]
public HttpResponseMessage Post([FromBody] object text)
If my post request body contains plain text ( i.e. should not be interpreted as json, xml, or any other special format ), then I thought I could just include following header to my request :
Content-Type: text/plain
However, I receive error :
No MediaTypeFormatter is available to read an object of type 'Object' from content with media type 'text/plain'.
If I change my controller action method signature to :
[HttpPost]
public HttpResponseMessage Post([FromBody] string text)
I get a slightly different error message :
No MediaTypeFormatter is available to read an object of type 'String' from content with media type 'text/plain'.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…