Код: Выделить всё
[TestMethod]
public async Task DebugStreamedContent()
{
Stream stream = null; // in real life the consumer of the stream is far away
var client = new HttpClient();
client.BaseAddress = new Uri("https://www.google.com/", UriKind.Absolute);
using (var request = new HttpRequestMessage(HttpMethod.Get, "/"))
using (var response = await client.SendAsync(request))
{
response.EnsureSuccessStatusCode();
//here I would return the stream to the caller
stream = await response.Content.ReadAsStreamAsync();
}
Assert.IsTrue(stream.CanRead); // FAIL if response is disposed so is the stream
}
В этом ответе говорится о том, что не утилизировать httpclient < /code>. Как насчет httprequestmessage и/или httpresponsemessage ?
Я что -то упускаю? Я надеюсь сохранить неосведомленность о поглощающем коде, но оставить все эти недовольные объекты вокруг, идут против года привычки!
Подробнее здесь: https://stackoverflow.com/questions/277 ... treamasync