Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP POST method treated like GET on WebApi

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

like image 447
A.Walsh Avatar asked Aug 12 '16 16:08

A.Walsh


1 Answers

Turns out I was using Http, instead of Https.

like image 108
A.Walsh Avatar answered Sep 19 '22 01:09

A.Walsh