How to get raw request body in ASP.NET?

前端 未结 6 1131
你的背包
你的背包 2021-01-07 16:12

In the HttpApplication.BeginRequest event, how can I read the entire raw request body? When I try to read it the InputStream is of 0 length, leadin

6条回答
  •  一整个雨季
    2021-01-07 16:58

    Pål's answer is correct, but it can be done much shorter as well:

    string req_txt;
    using (StreamReader reader = new StreamReader(HttpContext.Current.Request.InputStream))
    {
        req_txt = reader.ReadToEnd();
    }
    

    This is with .NET 4.6.

提交回复
热议问题