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."
}