简体   繁体   English

请求的资源不支持 http 方法“GET”,但使用“POST”

[英]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 的METHODGET ,应该是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.

相关问题 请求的资源不支持HTTP方法GET - The requested resource does not support HTTP method GET 请求的资源不支持 HTTP 方法“GET” - The requested resource does not support HTTP method 'GET' WebApi Post 方法总是返回“请求的资源不支持 http 方法 &#39;GET&#39;。” 状态:405 方法不允许 - WebApi Post Methods always Returns “The requested resource does not support http method 'GET'.” Status: 405 Method Not Allowed MVC和Web Api:请求的资源不支持http方法“ POST” - MVC and Web Api: The requested resource does not support http method 'POST' 如何修复 - 请求的资源不支持 http 方法“POST” - How to fix - The requested resource does not support http method 'POST' api发布错误:请求的资源不支持http方法&#39;GET&#39;.88 - Api Post error:The requested resource does not support http method 'GET'.88 c#webapi-请求的资源不支持http方法&#39;GET&#39; - c# webapi - The requested resource does not support http method 'GET' 所请求的资源在Visual Studio 2010中不支持HTTP方法“ GET” - The requested resource does not support HTTP method 'GET' in visual studio 2010 ASP.Net-请求的资源不支持http方法“ GET” - ASP.Net - Requested resource does not support http method 'GET' WebApi-请求的资源不支持http方法“ GET” - WebApi - The requested resource does not support http method 'GET'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM