1.HttpPOST要领中,,参数前添加[FromBody]
[HttpPost]
public string PostMethod([FromBody]string paras)
{
...
}
2.HttpPOST要领不撑持多个参数,如果前台传入多个参数,应在后台创建包罗参数的布局体(注意字段名称要一一对应),HttpPOST要领的参数为该布局体类型
错误要领
[HttpPost]
public string PostMethod([FromBody]string user,string pwd)
{
...
}
正确要领
public Struct User
{
public string user {get; set;}
public string pwd {get; set;}
}
[HttpPost]
public string PostMethod([FromBody]User userInfo)
{
...
}
3 注意注意!
public Struct User
{
public string user;
public string pwd;
} 这样是错的!!!必然要是属性!!!
public Struct User
{
public string user {get; set;}
public string pwd {get; set;}
} 这样才可以!!
WebAPI HttpPOST参数为null