1

I'm working on synchronizing two systems using their apis. How can i copy a massive response stream (of HttpWebResponse) to a request stream (of HttpWebRequest) without having OutOfMemoryException in C#.

CopyTo is throwing out of memory exception and I can't use byte arrays as well because they allocate contiguous memory blocks...

  • Might you please [edit] your question to share the `ToString()` output of the exception, including the exception type, message, full traceback and inner exception(s) if any? Also, a [mcve] showing code that reproduces the problem would help. – dbc Aug 12 '22 at 18:58
  • Possibly [ASP.NET Core Disable Response Buffering](https://stackoverflow.com/q/60607912) or [Non buffered output in ASP.NET Core 6](https://stackoverflow.com/q/72076958) are relevant. – dbc Aug 12 '22 at 18:59
  • 1
    Take a look at the second example in the accepted answer, which allocates a small buffer, reads into it repeatedly, and writes it to the destination stream in a loop. – Sergey Kalinichenko Aug 12 '22 at 19:00

0 Answers0