Why can't I read Http Request Input stream twice?

前端 未结 2 596
一向
一向 2020-12-15 18:18

I was putting in some debugging code to test some things, and then the debug code didn\'t behave as expected. The example below is a simplified code to demonstrate my questi

相关标签:
2条回答
  • 2020-12-15 19:10

    StreamReader calls Dispose on given stream when disposed. To leave the stream open use the appropriate constructor for the StreamReader. Or better yet, just copy it to a buffer. From MSDN:

    When reading from a Stream, it is more efficient to use a buffer that is the same size as the internal buffer of the stream.

    See this question for example.

    0 讨论(0)
  • 2020-12-15 19:10

    HttpContext.Current.Request.InputStream.Position=0;

    Once you read the position goes to last value, from there its trying to read second time. So before you read, set the position to zero.

    Hope it helps.

    0 讨论(0)
提交回复
热议问题