Skip to content

Instantly share code, notes, and snippets.

@lfgrando
Created March 1, 2021 12:43
Show Gist options
  • Save lfgrando/812c147c4190f714579d92456231e462 to your computer and use it in GitHub Desktop.
Save lfgrando/812c147c4190f714579d92456231e462 to your computer and use it in GitHub Desktop.
class Program
{
private static readonly HttpClient _httpClient = new HttpClient();
static void Main(string[] args)
{
var url = "";
byte[] fileBytes = null;
var httpMessage = new HttpRequestMessage(HttpMethod.Get, url);
var response = _httpClient.SendAsync(httpMessage).GetAwaiter().GetResult();
using (var stream = response.Content.ReadAsStreamAsync().GetAwaiter().GetResult())
using (var memStream = new MemoryStream())
{
stream.CopyTo(memStream);
fileBytes = memStream.ToArray();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment