[英]The requested resource does not support http method 'GET' but using 'POST'
My route is correctly configured as I already saw it in another questions.我的路线配置正确,因为我已经在另一个问题中看到了它。 Web API uses
MapHttpRoute
, and it uses System.Web.Http
. Web API 使用
MapHttpRoute
,它使用System.Web.Http
。 I decorated my Actions with [System.Web.Http.HttpPost]
but it seems not to work and it returns the error message:我用
[System.Web.Http.HttpPost]
装饰了我的动作,但它似乎不起作用,并返回错误消息:
The requested resource does not support http method 'GET'
请求的资源不支持 http 方法 'GET'
I tried this solution [System.Web.Http.AcceptVerbs("GET", "POST")]
as I see here on the same question.我在同一个问题上看到了这个解决方案
[System.Web.Http.AcceptVerbs("GET", "POST")]
。 The requested resource does not support HTTP method 'GET' and it worked. 请求的资源不支持 HTTP 方法“GET”并且它有效。
But on the API Help Page , this is what I see但是在API 帮助页面上,这就是我所看到的
the METHOD of the Action is GET
that that should be POST
. Action 的METHOD是
GET
,应该是POST
。
Maybe I am missing something that should not or should be implemented on the Action I am working with.也许我遗漏了一些不应该或应该在我正在使用的 Action 中实施的内容。
Here is my code in the Controller.这是我在控制器中的代码。
[HttpPost, Route("DestroySession/{userID}", Name = "DestroySession"), AcceptVerbs("GET" , "POST")]
public async Task<IHttpActionResult> DestroyUserSession(string userID)
{
SystemResult systemResult = new SystemResult();
await Task.Run(() => {
IAbstractLogic<UserInput, SystemResult> systemProcess = new LogoutLogic();
UserInput userInput = new UserInput
{
UserID = userID
};
systemResult = systemProcess.doProcess(userInput);
}).ConfigureAwait(false);
return Content(HttpStatusCode.OK, new
{
message = systemResult.ResultMessage, status = systemResult.ResultCode == 0
});
}
And here is my WebApiConfig
这是我的
WebApiConfig
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
Any help would be much appreciated.任何帮助将非常感激。 Regards
问候
Whooosh!哇! It seems that my code is working very fine.
看来我的代码工作得很好。 I just tested it in POSTMAN and it literally works.
我刚刚在 POSTMAN 中对其进行了测试,它确实有效。 All I can say is that if your request is to
POST
something.我可以说的是,如果您的请求是
POST
东西。 you need a third party application to test it out.您需要第三方应用程序来测试它。 Testing it on the browser alone gives you so much problem.
仅在浏览器上测试它会给您带来很多问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.