I wrote below async method to download file stream from WebApi. But while awaiting result at networkStrm = await httpClient.GetStreamAsync(_downloadRestUrl);
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. The underlying connection was closed: An unexpected error occurred on a receive.
async internal Task<Stream> DownloadAsync(string _downloadRestUrl)
{
Stream networkStrm = null;
try
{
var baseUrl = GetBaseUrl(_downloadRestUrl);
HttpClient httpClient = new HttpClient();
httpClient.Timeout = TimeSpan.FromMinutes(5);
httpClient.BaseAddress = baseUrl;
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/octet-stream"));
networkStrm = await httpClient.GetStreamAsync(_downloadRestUrl);
networkStrm.Seek(0, SeekOrigin.Begin);
}
catch (Exception ex)
{
}
return networkStrm;
}