Search code examples
c#postcontrollergetasp.net-web-api-routing

Why does Post work, but not Get, with the same route and args?


I have the following Controller code:

namespace PlatypusReports.Controllers
{
    [RoutePrefix("api/platypus")]
    public class PlatypusController : ApiController
    {
        [Route("{unit}/{begindate}")]
        [HttpPost]
        public void Post(string unit, string begindate)
        {
            . . .
        }

        [Route("{unit}/{begindate}")]
        [HttpGet]
        public string Get(string unit, string begindate)
        {
            . . .
        }
        . . .         

Calling the POST method works, but calling the GET method does not; in the latter case, I get, "405 Method Not Allowed - The requested resource does not support http method 'GET'."

I call them with the same exact URL from Postman:

http://localhost:52194/api/platypus/poisontoe/201509

...the only difference being I select "POST" it works, and when I select "GET" it doesn't.

Why would POST work but not GET? What do I have to change in my GET code to get it to be supported/allowed?


Solution

  • If you are using an apicontroller you don't need the decorators HttpPost and HttpGet. If you remove them it should then work.