C# Api Access

API Discussion
I try to get an access token and I following this guide https://develop.battle.net/documentation/guides/getting-started:

Here is my code:

using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://eu.battle.net/oauth/token"))
{
var base64authorization = Convert.ToBase64String(Encoding.ASCII.GetBytes("{client_id}:{client_secret}"));
request.Headers.TryAddWithoutValidation("Authorization", $"Basic {base64authorization}");

request.Content = new StringContent("grant_type=client_credentials", Encoding.UTF8, "application/x-www-form-urlencoded");

var response = System.Threading.Tasks.Task.Run(()=>httpClient.SendAsync(request)).Result;
test = response.RequestMessage.Headers.Authorization.Parameter;
}
using (var request = new HttpRequestMessage(new HttpMethod("GET"), "https://eu.api.blizzard.com/data/wow/token/?namespace=dynamic-eu"))
{
request.Headers.TryAddWithoutValidation("Authorization", "Bearer "+ test );

var response = System.Threading.Tasks.Task.Run(() => httpClient.SendAsync(request)).Result;
}
}

The first part to get an Authoriyation Parameter works. But if I try the request I got an 401 Unauthorized error.

Join the Conversation

Return to Forum