Yep I have debugged and the headers seem correct to me. I refactored a bit to new up a HttpClient specifically for a method call just to see what happens:
private void AddHeaders(HttpClient client)
{
StringValues token;
StringValues clientId;
var hasToken = headers.TryGetValue("Authorization", out token);
var hasClientId = headers.TryGetValue("Client-id", out clientId);
client.DefaultRequestHeaders.Add("Accept", "application/json");
if (hasToken)
{
var authToken = token.ToString().Replace("Bearer", "");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", authToken);
}
if (hasClientId)
{
client.DefaultRequestHeaders.Add("Client-id", clientId.ToString());
}
}
public async Task<int> GetFollowerCount(string userId)
{
using (var client = new HttpClient())
{
AddHeaders(client);
var response = await client.GetAsync($"http://api.twitch.tv/helix/users/follows?to_id={userId}");
var test = await response.Content.ReadAsStringAsync();
}
return 0;
}
Here are the DefaultRequestHeaders that are added to the HttpClient before the request is made:
{
Accept: application/json
Authorization: Bearer MYTOKEN
Client-id: kz6qzdszljw10pr9xynwv1acoo7dsy
}