我有一個Backbone.js應用程序,它調用我的一個WEB API自定義POST方法。下面是代碼到我的自定義後Fiddler - asp.net web api自定義POST
WebApiConfig.cs
config.Routes.MapHttpRoute
(
name: "UserAdministrationApi",
routeTemplate: "api/{controller}/PostUserInfo/{EmployeeDTO}",
defaults: new
{
EmployeeDTO = RouteParameter.Optional,
controller = "UserAdministration",
action = "PostUserInfo",
});
控制器
[HttpPost]
[ActionName("PostUserInfo")]
public HttpResponseMessage PostUserInfo(EmployeeDTO value)
{
// handling POST
}
EmployeeDTO
public class EmployeeDTO
{
public bool masAccess { get; set; }
public bool reportAccess { get; set; }
public string name { get; set; }
public string office { get; set; }
}
當我嘗試甚至去之前測試這提琴手用Backbone.js代碼測試它,我得到500內部錯誤。不知道什麼是錯的
//提琴手TEST
POST : http://localhost:56501/api/useradministration/PostUserInfo
Request Body
{
masAccess:"true"
reportAccess:"false"
}
感謝您的幫助
你用來測試這個的請求是什麼?另外'PostUserInfo'中的代碼可能是相關的。 – Andrei
值參數本身被設置爲空。 – Harish
這正是你如何用小提琴進行測試的嗎?由於默認情況下,fiddler以查詢字符串的形式期望body:'masAccess = true&reportAccess = false'。 – Andrei