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

xster
xster
May 4, 2012 · 1 min read

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.

xster

Collection of tech tips and learnings

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store