0

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'."}
5
  • When a client send a request there are three parts 1) URL 2) HTTP Headers 3) Body. A POST at client indicates there is a body and the contents length is the size of the body. You are getting an error at the server. The GET at server indicates the client has sent a request with a valid body. The body is optional. So error indicates the client has sent a body on a request and the server doesn't expect the request to have a body. Commented Nov 8, 2022 at 4:25
  • Are you calling the endpoint with GET? Commented Nov 8, 2022 at 4:38
  • 2
    The Api is [HttpPost] method and i guess you are calling it as GET method. That the reason for 405. Method not allowed. If its a GET Method and you can change to [HttpGet] Commented Nov 8, 2022 at 5:53
  • no @Chetan, it post request on postman. Commented Nov 8, 2022 at 10:40
  • @SH7 it is not connecting Commented Nov 8, 2022 at 10:45

2 Answers 2

2

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>
Sign up to request clarification or add additional context in comments.

Comments

1

Use [FromBody] attribute as below.

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

1 Comment

This wouldve been correct, if the code is not working on local.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.