HTTPPost MVC 4 web api

I am creating a mvc 4 web api but when I try to make a post to the web api the request returns

"The requested resource does not support http method 'POST'."

      

My request headers

User-Agent: Fiddler
Host: localhost:53393
Content-Length: 39
Content-Type: application/json

      

My request body

{
  "username":"",
  "password":""
}

      

Routes

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{id}",
            defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
        );
    }

      

And the method in my controller

[HttpPost]
public MethodResponse Authenticate(string username, string password)
{
    ConsoleServiceClient service = new ConsoleServiceClient();
    return service.Authenticate(username, password);
}

      

The url i am using

http://localhost:53393/api/service/authenticate

      

I'm still new to this but can't figure out why POST is not supported?

thank

+3


source to share


1 answer


Try using that http://localhost:53393/api/service

as your URI because you currently don't have a {action} segment in your API route.



+5


source







All Articles