我建立一个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