简体   繁体   中英

The requested resource does not support HTTP method 'GET' in visual studio 2010

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'

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM