Home > OS >  Post method returning error 405: does not support http Get Method
Post method returning error 405: does not support http Get Method

Time:11-10

I have an asp.net framework api endpoint that throws an error on IIS. it is a post method as thus:

    [HttpPost]
    [Route("api/ebonyiproxy/validateexpectedpaymentref")]
    public async Task<IHttpActionResult> GetResult(CustomerRequest request)
    {
        ...
        catch (Exception ex)
        {
            _logger.Report(ex.StackTrace, DateTime.Now);
            if (ex.InnerException != null)
                _logger.Report(ex.InnerException.StackTrace, DateTime.Now);

            return InternalServerError(ex);
        }

    }

Using postman to test; In the local, it returns valid response. In host, it throws the error bellow. Please help.

{"Message":"The requested resource does not support http method 'GET'."}

CodePudding user response:

Use [FromBody] attribute as below.

public async Task<IHttpActionResult> GetResult([FromBody]CustomerRequest request)

CodePudding user response:

Often this error is caused by the WebDAV module that try to handle this kind of requests. An easy solution is to remove it from modules and from handlers of the system.webServer section just inside your web.config file.

<system.webServer>
  <modules>
    <remove name="WebDAVModule" />
  </modules>
  <handlers>
    <remove name="WebDAV" />
  </handlers>
</system.webServer>
  • Related