所以這是讓我瘋狂。我正在做一些非常簡單的事情發送POST請求到我的web api。端點設置如下:C#.net核心Web API後參數始終爲空
[HttpPost]
[Route("locations")]
public async Task<IActionResult> PostLocations([FromBody]IEnumerable<Location>locations)
,我打出電話如下:
http://localhost:60254/api/Fetch/locations
With the body
{
"Locations": [
{
"LocationId": "111",
"ProductId": 110,
"Sku": "11131-LJK"
}
]
}
And header: content-type: application/json
現在又說,這是很簡單的東西,應該開箱,這fricking的框架變化正在搞亂一切。
現在,如果我得到的HttpContext和讀取體流直接
using (StreamReader reader = new StreamReader(HttpContext.Request.Body, Encoding.UTF8))
{
string body = reader.ReadToEnd();
}
我可以看到發送正確的身體,我有一個超級好形成JSON,我可以轉換成任何我想要的。所以問題是我錯過了這個端點不起作用?
什麼配置的web api項目模板沒有添加出這個框的工作?
這是一個asp.net核心的問題,還是asp.net的web api? –