public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
ILoggerFactory loggerFactory) { //允许body重用 app.Use(next => context => { context.
Request.EnableBuffering(); return next(context); }) } [HttpPost] public async
Task<string> Post() { //StreamReader sr = new StreamReader(Request.Body);
//string data = await sr.ReadToEndAsync(); string data = "";
//Request.EnableBuffering();可以实现多次读取Body Request.EnableBuffering(); StreamReader
sr= new StreamReader(Request.Body); data = await sr.ReadToEndAsync(); logger.
LogInformation("data=" + data); Request.Body.Seek(0, SeekOrigin.Begin); //再次读取
依然可以成功读到 Request.EnableBuffering(); StreamReader sr2 = new StreamReader(Request.
Body); string data2 = await sr2.ReadToEndAsync(); logger.LogInformation("data2="
+ data2); Request.Body.Seek(0, SeekOrigin.Begin); string header = $"请求头:\r\n";
foreach (var item in Request.Headers) { header += $"{item.Key}:{item.Value}\r\n"
; } logger.LogInformation(header); var ip = Request.Headers["X-Forwarded-For"].
FirstOrDefault(); if (string.IsNullOrEmpty(ip)) { //ip =
Request.HttpContext.Connection.RemoteIpAddress.ToString(); //ip =
Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString(); ip =
Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(); } logger.
LogInformation("ip=" + ip); }

技术
©2020 ioDraw All rights reserved
【C语言版】1011 A+B 和 C (15分)网络结构图多线程并发编程的基本问题java MySQL表的约束与数据库设计 详解STM32 RS485 modbus通讯源程序,亲测有效伪造ACK实现TCP数据注入JavaScript学习(返回值)vue3编写组件库发布到npm的过程不要再学java了,别人都在说你是傻子前端实习生必看(前端实习需要达到什么水平)