0

I have a web API (.NET Framework 4.0, MVC Web Application, visual studio 2010 sp1)

And there is my WebApiConfig code:

public static void Register(HttpConfiguration config)
{
    //config.MapHttpAttributeRoutes();

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

And for example this is one of my Controller's Methode Code:

[AcceptVerbs("Post")]
[ActionName("GetAccountTypeById")]
public static clsAccountType GetAccountTypeById(int AccountTypeId)
{
    SqlParameter[] param = { new SqlParameter("@Id", AccountTypeId) };
    DataTable dt = null;
    dt = Execute.ExecuteSelect("SP_GetAccountTypeById", param);
    if (dt.Rows.Count > 0)
    {clsAccountType item = new clsAccountType(Convert.ToInt32(dt.Rows[0]["Id"]), dt.Rows[0]["Name"].ToString());
        return item;
    }
    else
        return null;
}

The problem is when I call this URL:

http://localhost:1387/api/AccountType/GetAccountTypeById 

From browser show me this error:

The requested resource does not support http method 'GET'

Nkosi
  • 235,767
  • 35
  • 427
  • 472

1 Answers1

0

A browser cannot issue POST requests, so when you click the link in a browser you actually issue a GET request and that's why you see the error.

You need to use a tool like Postman which allows you to issue any type of request you need, in order to test your endpoints.

Andrei Dragotoniu
  • 6,155
  • 3
  • 18
  • 32