【发布时间】:2012-03-30 20:06:48
【问题描述】:
我正在构建一个 mvc 4 web api,但是当我尝试向 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
我还是新手,但不知道为什么不支持 POST?
谢谢
【问题讨论】:
-
你是如何发出post请求的?
-
我在fiddler中构建并点击执行
-
你的控制器叫ServiceController吗?
-
是的,正常的 GET 请求工作正常
标签: c# asp.net-mvc asp.net-web-api