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
2020诺贝尔生理或医学奖公布央行:微信支付宝和数字人民币不存在竞争关系layui.table动态获取表头和列表数据示例python中的gc回收机制安卓开发—根据顾客预算显示食物信息分享一场黑客帝国代码雨脚本,简单好玩!re模块常用方法三分钟看懂神经网络机器翻译OpenCV之IplImage详解逆向工程核心原理笔记(一)——Hello World-1