1,注入IHttpContextAccessor httpContexit
2,var req = _httpContext.HttpContext.Request;io
// 這句很重要,開啓讀取 否者下面設置讀取爲0會失敗coding
req.EnableBuffering();sso
using (var reader = new StreamReader(_httpContext.HttpContext.Request.Body, Encoding.UTF8, true, 1024, true))
{
var a = await reader.ReadToEndAsync();
id = JsonConvert.DeserializeObject<View>(a).Id;
}注入
// 這裏讀取過body Position是讀取過幾回 而此操做優於控制器先行 控制器只會讀取Position爲零次的di
req.Body.Position = 0;co