ASP.NET Core重复读取Request.Body

//HttpContext
context.Request.EnableRewind(); //创建缓冲区存放Request.Body的内容,从而允许反复读取Request.Body的Stream
using (var ms=new MemoryStream())
{
context.Request.Body.Position = 0;  //请求到控制器之后 Position重置0 context.Request.Body.CopyTo(ms); context.Request.Body.Position
= 0; using (var st = new StreamReader(ms)) { st.BaseStream.Position = 0; body = st.ReadToEnd().Replace("\n", ""); } }

 

posted @ 2019-11-20 14:50  漫天行  阅读(942)  评论(0编辑  收藏  举报