简体   繁体   English

所请求的资源在Visual Studio 2010中不支持HTTP方法“ GET”

[英]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) 我有一个Web API(.NET Framework 4.0,MVC Web应用程序,visual studio 2010 sp1)

And there is my WebApiConfig code: 还有我的WebApiConfig代码:

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: 例如,这是我的控制器的Methode代码之一:

[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: 问题是当我调用此URL时:

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

From browser show me this error: 从浏览器中向我显示此错误:

The requested resource does not support http method 'GET' 请求的资源不支持http方法'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. 浏览器无法发出POST请求,因此,当您单击浏览器中的链接时,您实际上会发出GET请求,这就是您看到错误的原因。

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. 您需要使用诸如Postman之类的工具,该工具可让您发出所需的任何类型的请求,以测试端点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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