Asp.net web api GET和POST的ASP.NET Web API方法

Asp.net web api GET和POST的ASP.NET Web API方法,asp.net-web-api,Asp.net Web Api,我的API中有以下方法: [HttpGet] public HttpResponseMessage ExecuteCommand() { // logic } 此方法当前仅为http GET方法提供服务。我还希望它响应http POST方法-这可能吗?还是我必须复制这个方法 谢谢你可以这样做 [AcceptVerbs("Get", "Post")] public HttpResponseMessage ExecuteCommand() { // logic } 这是可能的,因

我的API中有以下方法:

[HttpGet]
public HttpResponseMessage ExecuteCommand()
{
    // logic
}
此方法当前仅为http GET方法提供服务。我还希望它响应http POST方法-这可能吗?还是我必须复制这个方法


谢谢你可以这样做

[AcceptVerbs("Get", "Post")]
public HttpResponseMessage ExecuteCommand()
{
    // logic
}
这是可能的,因为构造函数看起来像这样,并且接受字符串数组

public AcceptVerbsAttribute(
    params string[] verbs
)