MVC controller : get JSON object from HTTP body?

前端 未结 5 572
闹比i
闹比i 2020-11-28 06:46

We have an MVC (MVC4) application which at times might get a JSON events POSTed from a 3rd party to our specific URL (\"http://server.com/events/\"). The JSON event is in th

5条回答
  •  悲哀的现实
    2020-11-28 07:33

    Once you define a class (MyDTOClass) indicating what you expect to receive it should be as simple as...

    public ActionResult Post([FromBody]MyDTOClass inputData){
     ... do something with input data ...
    }
    

    Thx to Julias:

    Parsing Json .Net Web Api

    Make sure your request is sent with the http header:

    Content-Type: application/json

提交回复
热议问题