netcore 启用EnableRewind倒带解决只能读取一次body的问题

使用以下方法:

Current.Request.EnableRewind();
Stream reqStream = Current.Request.Body;
byte[] buffer = new byte[Current.Request.ContentLength.Value];
reqStream.Read(buffer, 0, buffer.Length);
inputString = Encoding.UTF8.GetString(buffer);
Current.Request.Body.Position = 0;

注意: 不能通过以下方法读取body,否则倒带功能将失效

Current.Request.EnableRewind();
Stream reqStream = Current.Request.Body;
using (StreamReader reader = new StreamReader(reqStream))
{
    inputString = reader.ReadToEnd();
}
Current.Request.Body.Position = 0;
上一篇:STM32+W5500网络通信


下一篇:Perf / Ring Buffer对比