我有来自http web客户端(c#)的POST请求的web api。我正在使用chrome的REST控制台来调试我的web api。 当我在querystring中传递参数时它工作正常,但是当我将参数作为Raw Body传递时它不起作用。 我不知道我错过了什么。
以下是我的代码。
控制器:
[HttpPost]
public JsonResult VerifyUserAuth([Bind(Prefix = "t"), Required] string token,
[Bind(Prefix = "ApplicationGUID"), Required] string applicationGUID,
string userID,
string password)
{
return Json(NotificationsSecurity.VerifyUserAuth(_connectionstring, userID, password),
JsonRequestBehavior.AllowGet);
}
当我在VS调试器中调试它并将参数作为RAW主体传递时,它显示为null。但是当我作为查询字符串传递时,我正在接收所有参数。
答案 0 :(得分:0)
当您指定多个简单类型时,Web API默认不使用格式化程序。格式化程序知道如何将主体有效负载映射到表示模型的对象实例。对于简单类型,模型绑定器主要用于URI和RouteData参数。我会对您的操作进行一些小改动,以正确解析有效负载。
public class VerifyUserAuthModel
{
public string Token { get; set; }
public string ApplicationGUID { get; set; }
public string UserID { get; set; }
public string Password { get; set; }
}
public JsonResult VerifyUserAuth(VerifyUserAuthModel model)
{
}