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