The requested resource does not support HTTP method 'GET'

前端 未结 5 652
你的背包
你的背包 2020-12-02 15:21

My route is correctly configured, and my methods have the decorated tag. I still get \"The requested resource does not support HTTP method \'GET\'\" message?



        
相关标签:
5条回答
  • 2020-12-02 15:29

    Resolved this issue by using http(s) when accessing the endpoint. The route I was accessing was not available over http. So I would say verify the protocols for which the route is available.

    0 讨论(0)
  • 2020-12-02 15:30

    just use this attribute

    [System.Web.Http.HttpGet]
    

    not need this line of code:

    [System.Web.Http.AcceptVerbs("GET", "POST")]
    
    0 讨论(0)
  • 2020-12-02 15:31

    I was experiencing the same issue.. I already had 4 controllers going and working just fine but when I added this one it returned "The requested resource does not support HTTP method 'GET'". I tried everything here and in a couple other relevant articles but was indifferent to the solution since, as Dan B. mentioned in response to the answer, I already had others working fine.

    I walked away for a while, came back, and immediately realized that when I added the Controller it was nested under the "Controller" class and not "ApiController" class that my other Controllers were under. I'm assuming I chose the wrong scaffolding option to build the .cs file in Visual Studio. So I included the System.Web.Http namespace, changed the parent class, and everything works without the additional attributes or routing.

    0 讨论(0)
  • 2020-12-02 15:42

    In my case, the route signature was different from the method parameter. I had id, but I was accepting documentId as parameter, that caused the problem.

    [Route("Documents/{id}")]   <--- caused the webapi error
    [Route("Documents/{documentId}")] <-- solved
    public Document Get(string documentId)
    {
      ..
    }
    
    0 讨论(0)
  • 2020-12-02 15:45

    Please use the attributes from the System.Web.Http namespace on your WebAPI actions:

        [System.Web.Http.AcceptVerbs("GET", "POST")]
        [System.Web.Http.HttpGet]
        public string Auth(string username, string password)
        {...}
    

    The reason why it doesn't work is because you were using the attributes that are from the MVC namespace System.Web.Mvc. The classes in the System.Web.Http namespace are for WebAPI.

    0 讨论(0)
提交回复
热议问题