ASP.NET web api cannot get application/x-www-form-urlencoded HTTP POST

前端 未结 6 611
无人共我
无人共我 2020-12-01 10:53

I\'m new to web-api. I want to receive a HTTP POST data using web-api. The content-type is application/x-www-form-urlencoded, and the request body is like:

6条回答
  •  执笔经年
    2020-12-01 11:06

    You should create an object of your data like:

    public class Device
    {
      public string mac {get;set;}
      public string model {get;set;}
    }
    

    then change your controller's action method like this and pass your object to this method from consume

    public void Post(Device deviceData)
    {
        // You can extract data like deviceData.mac, deviceData.model etc
        data.Add(deviceData);
    }
    

    You can use one of the popular library json.net for serialize/deserialize of json object in C#

提交回复
热议问题