spotify / web-api

This issue tracker is no longer used. Join us in the Spotify for Developers forum for support with the Spotify Web API ➡️ https://community.spotify.com/t5/Spotify-for-Developers/bd-p/Spotify_Developer
983 stars 79 forks source link

Bad request error code 400 C# #1546

Open PiepsC opened 4 years ago

PiepsC commented 4 years ago

Description issue

Trying to obtain access token through logging in a specific user, did everything described in the docs. Tried using curl and worked perfectly, but returns "bad request" when trying to replicate the concept programmatically. I've tried pretty much all available .NET solutions I could find on SO but I can't get it to work.

Source code:

var plain = System.Text.Encoding.UTF8.GetBytes(_login);
            string loginb = System.Convert.ToBase64String(plain);
            HttpClient sClient = new HttpClient();
            sClient.BaseAddress = new Uri(_URL);
            sClient.DefaultRequestHeaders.Accept.Add(
            new MediaTypeWithQualityHeaderValue("application/json"));
            sClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", loginb);
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "");
            request.Content = new StringContent("grant_type=client_credentials", System.Text.Encoding.UTF8, "application/x-www-form-urlencoded");
            await sClient.SendAsync(request)
            .ContinueWith(responseTask =>
            {
                Console.WriteLine("{0}", responseTask.Result);
            });

All of the above user inputs are correct as curl works(ie "_URL", "_login").