ASP.NET

Read Raw JSON Data from HTTP POST for ASP.NET MVC 4 Web API

The Web API is a good step catching up to Ruby on Rails and Django but isn’t nearly as well documented. If your posted data doesn’t match exactly a model object, it’s hard to figure out how to just get all the data out and process it yourself. Inside the

public void Post()

tag, you can have access to a Request member from ApiController and with it, you can do

JsonObject input = Request.Content.ReadAsAsync().Result;

to get the data out. A key detail is that if you do so, you cannot put any parameters in the Post method declaration or it will try to bind it to which ever parameter type you specified.

 Scroll to top