8.18Using LoadIntoBufferAsync to Cache Response Content
Created on Aug 18, 2026~3 min read
When sending HTTP remote requests, the response content is returned as a stream by default and can only be read once. If you need to read the response content multiple times in different places (for example, for logging, content validation and business processing at the same time), reading the stream directly will cause subsequent reads to return empty or throw an exception.
In this case, you can call the HttpContent.LoadIntoBufferAsync() method to buffer the response content into memory, thereby enabling subsequent repeated reads.
var response = await httpRemoteService.GetAsync("https://furion.net/");// Load the response content into the memory bufferawait response.Content.LoadIntoBufferAsync();// The response content can now be read multiple timesvar content1 = await response.Content.ReadAsStringAsync();var content2 = await response.Content.ReadAsStringAsync();