500 ошибок при попытке обновить токен Spotify C#
Я получаю 500 ошибок при попытке обновить мой токен Spotify.
error: {"error": "server_error"}
запрос:
POST https://accounts.spotify.com/api/token HTTP / 1.1 Авторизация: Basic ZWM.....WI= Хост: accounts.spotify.com Длина контента: 170 Ожидается: 100-продолжение Соединение: Keep-Alive
grant_type = refresh_token & refresh_token = AQA9..... P5QC
код:
string request = "https://accounts.spotify.com/api/token";
StringBuilder sbOutput = new StringBuilder();
StringBuilder sbBody = new StringBuilder();
sbBody.Append("grant_type=refresh_token");
sbBody.Append("&refresh_token=" + spotifyToken.RefreshToken);
//sbBody.Append("&client_id=" + "ec41.....19");
//sbBody.Append("&client_secret=" + "9b...5b");
string clientIdAndSecret = "ec....19:9ba.....e5b";
var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(clientIdAndSecret);
string clientIdAndSecretBase64 = System.Convert.ToBase64String(plainTextBytes);
Dictionary<string, string> headers = new Dictionary<string, string>();
headers["Authorization"] = "Basic " + clientIdAndSecretBase64;
response = SendRequest("POST", request, sbBody.ToString(), headers, ref sbOutput);
Метод SendRequest:
if (!string.IsNullOrEmpty(url))
{
using (var client = new HttpClient())
{
//Create request URI
Uri requestURI = new Uri(url);
//Create Stream from the content
Stream bodyStream = new MemoryStream(Encoding.UTF8.GetBytes(body ?? ""));
HttpContent requestContent = new StreamContent(bodyStream);
//Headers
foreach (KeyValuePair<string, string> pair in headers)
{
client.DefaultRequestHeaders.Add(pair.Key, pair.Value);
}
Task<HttpResponseMessage> responseTask;
switch (httpWebRequestMethod.ToUpper())
{
case "POST":
responseTask = client.PostAsync(requestURI, requestContent);
break;
case "GET":
responseTask = client.GetAsync(requestURI);
break;
case "DELETE":
responseTask = client.DeleteAsync(requestURI);
break;
case "PUT":
responseTask = client.PutAsync(requestURI, requestContent);
break;
default:
return HttpStatusCode.Unused;
}
//Lets wait
responseTask.Wait();
if (responseTask.IsCompleted)
{
HttpResponseMessage response = responseTask.Result;
string resultBody = response.Content.ReadAsStringAsync().Result;
sbOutput.Append(resultBody);
return response.StatusCode;
}
}
}
return HttpStatusCode.Unused;
}
любая помощь будет высоко ценится, так как я готов ударить головой о стену!
Спасибо:)