1
我發現了一個blog post,它顯示瞭如何以字符串形式接收POST JSON。什麼是ASP.NET核心相當於HttpRequestMessage?
我想知道什麼是應該做同樣的事情在REST Post方法下面的代碼在一個控制器的新土辦法:
public async Task<HttpResponseMessage> Post(HttpRequestMessage request)
{
var jsonString = await request.Content.ReadAsStringAsync();
// Do something with the string
return new HttpResponseMessage(HttpStatusCode.Created);
}
另一種選擇波紋管不工作對我來說,我覺得因爲我在請求頭中沒有使用Content-Type: application/json
(不能改變這個),我得到了415。
public HttpResponseMessage Post([FromBody]JToken jsonbody)
{
// Process the jsonbody
return new HttpResponseMessage(HttpStatusCode.Created);
}