I've been creating a WebApi controller, and I'm trying to use a HttpPost request to submit a new user for registration. This works fine on my localhost, but when I publish it to Azure I get a 405 method not allowed error with the message: "The requested resource does not support http method 'GET'".
I use postman to check the actions, and so I used generate code to see the request, which is as follows:
POST /api/account/register/student HTTP/1.1
Host: www.l3cture.com
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 27c1b2ab-96ad-4a99-b271-4030402768e7
So I can clearly see that the request is a POST. And the following is the controller action code with its attributes (I've currently simplified it so that no models are posted, and the same behaviour occurs)
[HttpPost]
[Route("register/student")]
[AllowAnonymous]
public async Task<IHttpActionResult> PostStudent(/*RegisterStudent model*/)
{
//Implementation of register
return Ok();
}
I've checked the namespace of the attributes, and it is System.Web.Http, so it's not being confused with the MVC namespace.
The interesting thing is that when I change the method to be HttpGet, and POST to it using postman, I receive a status 200. It's almost like the HttpPost requests are all being treated like HttpGet by my controller.
I've used HttpPut and HttpDelete in other places, and they all work fine.
I'm unsure how to tackle this problem, and was wondering if anyone had any ideas? Please let me know if I need to post more code for clarification.
Thanks in advance
Turns out I was using Http, instead of Https.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With