Your problem is to do with headers. But, let's start you on the right track and teach you one of the more modern ways of making Http Requests using DI, Services, and IHttpClientFactory
.
Service
public class MyFunkyService
{
private readonly IHttpClientFactory _clientFactory;
public MyFunkyService(IHttpClientFactory clientFactory)
=> _clientFactory = clientFactory;
public async Task<byte[]> GetSomeFunkyThingAsync()
{
using var client = _clientFactory.CreateClient();
using var request = new HttpRequestMessage(HttpMethod.Get, "http://aplweb.soriana.com/foto/fotolib//14/7503003936114/7503003936114-01-01-01.jpg");
request.Headers.Accept.ParseAdd("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
request.Headers.AcceptEncoding.ParseAdd("gzip, deflate");
using var response = await client
.SendAsync(request)
.ConfigureAwait(false);
response.EnsureSuccessStatusCode();
return await response
.Content
.ReadAsByteArrayAsync()
.ConfigureAwait(false);
}
}
Set up
var provider = new ServiceCollection()
.AddHttpClient()
.AddSingleton<MyFunkyService>()
.BuildServiceProvider();
Usage
// this would be injected
var myClient = provider.GetRequiredService<MyFunkyService>();
var result = await myClient.GetSomeFunkyThingAsync();
Note : there are many many more variations on how you could do this. However at least you are not learning the old and busted ways of doing things