公司有位大神发现的问题,给出的解决方案,在此记录一下。   在 http-Post请求,Post Body中的数据量过大时出现的问题 随笔 第1张ASP.NET中,当Post Body中的数据量过大的时候(超过maximum request length),.NET会把超过的部分放入Buffered Stream中,在读取完这个Buffered Stream,才能读取Request的InputStream,否则,会抛出异常 http-Post请求,Post Body中的数据量过大时出现的问题 随笔 第2张 。
public void ResponseHandler(HttpContext httpContext)
{
    var s=new StreamReader(this.httpContext.Request.InputStream);//会报错
    var r=s.ReadToEnd();
}

应改为:

public void ResponseHandler(HttpContext httpContext)
{  
    var streamReader = new StreamReader(stream=Request.GetBufferedInputStream());
    var streamRead = streamReader.ReadToEnd();

    var s=new StreamReader(this.httpContext.Request.InputStream);
    var r=s.ReadToEnd();
}

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

 

 

   
扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄