Fiddler - asp.net web api自定义POST

Har*_*ish 2 c# asp.net backbone.js asp.net-web-api

我有一个Backbone.js应用程序,它正在调用我的一个WEB API自定义POST方法.这是我的自定义POST的代码

WebApiConfig.cs

config.Routes.MapHttpRoute
            (
                name: "UserAdministrationApi",
                routeTemplate: "api/{controller}/PostUserInfo/{EmployeeDTO}",
                defaults: new
                {
                    EmployeeDTO = RouteParameter.Optional,
                    controller = "UserAdministration",
                    action = "PostUserInfo",
                });
Run Code Online (Sandbox Code Playgroud)

调节器

        [HttpPost]
        [ActionName("PostUserInfo")]
        public HttpResponseMessage PostUserInfo(EmployeeDTO value)
        {
            // handling POST
        }
Run Code Online (Sandbox Code Playgroud)

EmployeeDTO

   public class EmployeeDTO
   {
    public bool masAccess { get; set; }
    public bool reportAccess { get; set; }
    public string name { get; set; }
    public string office { get; set; }
   }
Run Code Online (Sandbox Code Playgroud)

当我在使用Backbone.js代码测试它之前尝试在Fiddler中测试它时,我得到500内部错误.不确定是什么问题

// FIDDLER TEST

POST : http://localhost:56501/api/useradministration/PostUserInfo



Request Body

  {
     masAccess:"true"
     reportAccess:"false"
   }
Run Code Online (Sandbox Code Playgroud)

感谢您的帮助

Rya*_*n M 6

一些东西:

正如Andrei所提到的,EmployeeDTO不应该成为routeTemplate的一部分.

根据JSONlint.com,您的请求正文不是有效的JSON.尝试

{
  "masAccess": "true",
  "reportAccess": "false"
}
Run Code Online (Sandbox Code Playgroud)

此外,您可能需要将标头添加Content-Type: application/json到您的Fiddler请求中.