Access Raw Request Body

后端 未结 4 1441
北恋
北恋 2021-01-04 12:59

I\'m trying to access a request\'s raw input body/stream in ASP.net 5. In the past, I was able to reset the position of the input stream to 0 and read it into a memory strea

4条回答
  •  半阙折子戏
    2021-01-04 13:23

    You need to call Request.EnableRewind() to allow the stream to be rewound so you can read it.

    string bodyAsString;
    Request.EnableRewind();
    using (var streamReader = new StreamReader(Request.Body, Encoding.UTF8))
    {
        bodyAsString = streamReader.ReadToEnd();
    }
    

提交回复
热议问题