HTTPPost MVC 4 web api

Arm*_*and 3 c# asp.net-mvc asp.net-web-api

我正在构建一个mvc 4 web api,但是当我尝试向web api发帖时,请求返回

"The requested resource does not support http method 'POST'."
Run Code Online (Sandbox Code Playgroud)

我的请求标题

User-Agent: Fiddler
Host: localhost:53393
Content-Length: 39
Content-Type: application/json
Run Code Online (Sandbox Code Playgroud)

我的请求机构

{
  "username":"",
  "password":""
}
Run Code Online (Sandbox Code Playgroud)

路线

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }
Run Code Online (Sandbox Code Playgroud)

和我的控制器中的方法

[HttpPost]
public MethodResponse Authenticate(string username, string password)
{
    ConsoleServiceClient service = new ConsoleServiceClient();
    return service.Authenticate(username, password);
}
Run Code Online (Sandbox Code Playgroud)

我使用的URL

http://localhost:53393/api/service/authenticate
Run Code Online (Sandbox Code Playgroud)

我还是新手,但无法弄清楚为什么不支持POST?

谢谢

Dar*_*ler 5

尝试使用http://localhost:53393/api/service您的URI,因为您目前在API路线中没有{action}细分.