.net core 3.0 在过滤器读取request.body 里的请求,controller[FromBody]读取不到参数,解决办法
2024-09-01 03:53:02
1,注入IHttpContextAccessor httpContex
2,var req = _httpContext.HttpContext.Request;
// 这句很重要,开启读取 否者下面设置读取为0会失败
req.EnableBuffering();
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为零次的
req.Body.Position = 0;
最新文章
- protocol buffers vs json vs XML
- hive 调优总结
- Default Title
- c++ 覆盖、重载与隐藏
- WinForm中DataGridView显示更新数据--人性版
- [原创]PCB知识补充
- BZOJ-2038 小Z的袜子(hose) 莫队算法
- android中正确导入第三方jar包
- King&#39;s Quest
- 基于GBT28181:SIP协议组件开发-----------第二篇SIP组件开发原理
- JavaScript学习笔记(一)对象和属性
- C#学习笔记-适配器模式
- windows10,redhat6.5下python3.5.2使用cx_Oracle链接oracle
- user-agent | what is the ";user-agent"; ?
- 依赖注入[7]: .NET Core DI框架[服务注册]
- 【原创】uC/OS 中LES BX,DWORD PTR DS:_OSTCBCur的作用及原理
- 在 delphiXE 10.2 上安装 FR5.4.6
- C# 操作符 <;<; 与 >;>;
- sql语句中having的作用是?
- [转]How to tell NLog to log exceptions?