0
返回JSON我正在开发中,我有一个类型的资源型B的拥有资源POST操作以JSON和使用ASP.NET
我想开发一个API用于获取有关的统计Web服务A,但只考虑其Bs的一个子集。
所以我有一条路线取A的ID,Bs的ID集合,并返回统计。我会使用它像下面这样:
POST /api/StatsAboutA/{aId}
JSON payload:
[1, 4, 12]
而且它会返回类似的东西:
[
{"key": ..., "value": ...},
...
]
这里是我的控制器:
class StatsAboutAController : ApiController
{
// ...
// POST api/StatsAboutA/{aId}
[HttpPost]
public Stats Post(long aId, IEnumerable<long> bIds)
{
A a = _aRepository.SelectById(aId);
if (a == null)
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
}
return _aRepository.CollectStats(a, bIds);
}
// ...
}
我不能设法配置我的路由器,以便我的控制器匹配我的路由。
以下是错误消息我得到:
{
"message": "No HTTP resource was found that matches the request URI 'http://localhost:51398/api/StatsAboutA/1'.",
"messageDetail": "No action was found on the controller 'StatsAboutA' that matches the request."
}