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

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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