我建立一個MVC 4個Web API,但是當過我嘗試做一個發佈到網絡API請求返回HTTPPost MVC 4個Web API
"The requested resource does not support http method 'POST'."
我的請求頭
User-Agent: Fiddler
Host: localhost:53393
Content-Length: 39
Content-Type: application/json
我請求體
{
"username":"",
"password":""
}
路線
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 }
);
}
而且在我的控制器
[HttpPost]
public MethodResponse Authenticate(string username, string password)
{
ConsoleServiceClient service = new ConsoleServiceClient();
return service.Authenticate(username, password);
}
的方法我用
http://localhost:53393/api/service/authenticate
的URL我仍然新本,但無法弄清楚,爲什麼不支持POST?
感謝
你如何提出要求? – gdoron 2012-03-14 11:08:58
我在提琴手中構建它,然後單擊執行 – Armand 2012-03-14 11:12:42
您的控制器是否稱爲ServiceController? – 2012-03-14 11:16:55