My code looks like:
_req = new HttpRequestMessage(HttpMethod.Get, _uri);
_response = await _httpClient.SendAsync(_req, HttpCompletionOption.ResponseHeadersRead).ConfigureAwait(false);
var rawResponse = new byte[_maxContentLength];
using (var responseStream = await _response.Content.ReadAsStreamAsync().ConfigureAwait(false))
{
int read;
int offset = 0;
do
{
read = await responseStream.ReadAsync(rawResponse, 0, rawResponse.Length).ConfigureAwait(false);
html += Encoding.UTF8.GetString(rawResponse, 0, read);
offset += read;
if (offset > _maxContentLength)
{
return Error("Too big");
}
} while (read != 0);
}
and is "return Error()" enough to free stream and sockets to get next url?
//edit:
For some pages await responseStream.ReadAsync
hangs and never returns