【发布时间】:2015-08-06 18:58:28
【问题描述】:
我正在尝试使用以下原型编写 API:
[HttpPost]
public ApplicationStatus appLogIn(string id, UserCredentials userCredentials = null)
但是当我向这个 API 发出请求时,无论有没有userCredentials,我都会收到以下错误,响应代码为500
{
"Message": "An error has occurred.",
"ExceptionMessage": "Optional parameter 'userCredentials' is not supported by 'FormatterParameterBinding'.",
"ExceptionType": "System.InvalidOperationException",
"StackTrace": null
}
如果我不将 userCredentials 设为可选,则一切正常。 userCredential 定义如下:
public class UserCredentials
{
public string password { get; set; }
public string username { get; set; }
}
【问题讨论】:
标签: asp.net asp.net-web-api http-post restful-architecture