1

I need to be able to consume some JSON data in a POST request from another web app. I have tried looking at the various methods on the Request class, but nothing seems to give me the JSON I need.

Using Request.Form will not work, since it is not coming from a form, but another web app. The content type is application/json, and from examining the whole HTTP request, I know the JSON is in there. What is the best way to get at this JSON data?

Note: I am working from within an action on a controller.

Corey Larson
  • 1,577
  • 18
  • 39

2 Answers2

1

Since you are consuming data from another web app I would use a REST web service instead of a controller in an MVC application. You cans use the ASP.NET Web API which makes it easy to setup a REST web API and it is tightly integrated in with MVC 4, which is now in Beta. If the communication is cross domain (i.e. different servers and/or ports) you will need to use JSONP. You can go to this StackOverflow QA for directions on how to use JSONP with Web API.

Community
  • 1
  • 1
Kevin Junghans
  • 17,475
  • 4
  • 45
  • 62
1

I think you can get your JSON from your model parameter inside the Action of the Controller. Check out this article that explains a bit of what I mean.

You can also read this one for reference

Mau Sánchez
  • 154
  • 1
  • 6