To be honest, if you have the chance, I would ditch the use of HttpWebResponse altogether and go with the newer .NET approach of using HttpClient. Your code may end up looking something like this:
public class HttpRequestManager
{
private readonly IHttpClientFactory httpClientFactory;
public HttpRequestManager(IHttpClientFactory httpClientFactory)
{
this.httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
}
public async Task<string> GetJSONFromUrlAsync(string url, CancellationToken token = CancellationToken.None)
{
using (var client = httpClientFactory.CreateClient());
using (HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url));
using (var response = await client.SendAsync(request, token));
response.EnsureSuccessStatusCode();
string rawData = await response.Content.ReadAsStringAsync();
return rawData;
}
}
Note that there may be some minor syntax mistakes in this as I just knocked this up in notepad to demonstrate the technique. Get this working and you have none-blocking download capacity.