Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Created Unassigned: StreamContent#ReadAsString is affected by stream position [1553]

$
0
0
Calling ReadAsStreamAsync and then manipulating the resulting stream will change the data that's used by other ReadAs* methods on StreamContent. What's worse is that StreamContent does buffering, so once you call a method like ReadAsStringAsync, the content is effectively 'stuck' in the buffer. Resetting the stream doesn't help.

In this example, post some text like "Hello, World!"

The string that's read from the content is "ello, World!" -- and it's cached in the buffer.

`
public async Task<HttpResponseMessage> PostRequest(HttpRequestMessage request)
{
var stream = await request.Content.ReadAsStreamAsync();
stream.Seek(1L, SeekOrigin.Begin);

var content = await request.Content.ReadAsStringAsync();

stream.Seek(0L, SeekOrigin.Begin);
content = await request.Content.ReadAsStringAsync();


return request.CreateResponse(HttpStatusCode.OK);
}
`

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>