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

前端 未结 6 610
无人共我
无人共我 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:21

    create a model

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

    and use .net JavaScriptSerializer().Deserialize

    public void Post([FromBody]string formData){
        MyClass obj = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize(formData);
        //get mac and model by obj.mac obj.model
    }
    

    cheers :)

提交回复
热议问题