Em .NET, o HttpClient é o padrão de mercado para chamadas de API — o exemplo abaixo funciona em qualquer projeto .NET 6 ou superior.
Exemplo de requisição
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", Environment.GetEnvironmentVariable("SCRAPEGRAM_TOKEN"));
var resposta = await client.GetAsync(
"https://scrapegram.cloud/api/v1/instagram/profile?username=nike");
if (resposta.IsSuccessStatusCode)
{
var json = await resposta.Content.ReadAsStringAsync();
Console.WriteLine(json);
}
else
{
Console.WriteLine($"Erro HTTP {(int)resposta.StatusCode}");
}
Desserializando com System.Text.Json
var perfil = await resposta.Content.ReadFromJsonAsync();
var seguidores = perfil.GetProperty("followers").GetInt64();
Boa prática: HttpClient como singleton
Em aplicações ASP.NET, registre o HttpClient via IHttpClientFactory em vez de instanciar um novo a cada chamada — evita esgotamento de sockets sob carga.