ASP.NET Core中读取Body入参内容

 

            #region 读取body内容
            // 获取请求参数
            Request.EnableBuffering();
            var postJson = "";
            var stream = Request.HttpContext.Request.Body;
            long? length = Request.HttpContext.Request.ContentLength;
            if (length != null && length > 0)
            {
                // 使用这个方式读取,并且使用异步
                StreamReader streamReader = new StreamReader(stream, Encoding.UTF8);
                postJson = streamReader.ReadToEndAsync().Result;
            }
            Request.HttpContext.Request.Body.Position = 0;
            #endregion

 

你可能感兴趣的:(.NET,Core,ASP.NET,Core)