如何将JSON POST数据作为对象传递给WebAPI方法?
public class CustomersController : ApiController { public object Post([FromBody] Customer customer) { return Request.CreateResponse(HttpStatusCode.OK, new { customer = customer }); } }}public class Customer { public string company_name { get; set; } public string contact_name { get; set; } }
POST http://localhost:52216/api/customers HTTP/1.1Accept: application/json, text/javascript, */*; q=0.01 X-Requested-With: XMLHttpRequest Content-Type: application/x-www-form-urlencoded; charset=UTF-8 {"contact_name":"sdfsd","company_name":"ssssd"}
相关分类