public GetByteArrayAsync ( |
||
requestUri | ||
return | Task |
using System; using System.Net.Http; using System.Threading.Tasks; class Program { static HttpClient client = new HttpClient(); static async Task Main(string[] args) { byte[] responseBody = await client.GetByteArrayAsync("http://example.com/image.png"); Console.WriteLine($"The image has {responseBody.Length} bytes."); } }
using System; using System.Net.Http; using System.Threading.Tasks; class Program { static HttpClient client = new HttpClient(); static async Task Main(string[] args) { HttpResponseMessage response = await client.GetAsync("http://example.com/redirect"); byte[] responseBody = await response.Content.ReadAsByteArrayAsync(); Console.WriteLine($"The response has {responseBody.Length} bytes."); } }This example shows how to use GetByteArrayAsync in conjunction with HttpResponseMessage to handle HTTP redirects. The package library for this example is also System.Net.Http.