2017-02-28 138 views
1

我想请求使用下的“客户端凭证流”上Spotify developer page规定的程序一Spotify的访问令牌,故障请求Spotify的访问令牌[错误的请求]

这是我目前的执行(目前回报HTTP 400错误):

using (var client = new HttpClient()) 
{ 
    var requestBody = new StringContent(
     "grant_type:client_credentials", 
     Encoding.UTF8, 
     "application/x-www-form-urlencoded"); 

    var requestEncrypted = Convert.ToBase64String(
     Encoding.UTF8.GetBytes(ClientId + ":" + ClientSecret)); 

    client.DefaultRequestHeaders.Add(
     "Authorization", 
     $"Basic {requestEncrypted}"); 

    var tokenResult = await client.PostAsync(TokenEndpoint, requestBody); 
} 

我曾尝试其他方法用于格式化请求体包括作为JSON(注意:在改变编码类型为“应用/ JSON”的结果在一个http 415错误(媒体不支持)

+0

什么是您的TokenEndpoint值? –

+0

@ShaunLuttin'https://accounts.spotify.com/api/token' –

回答

2

首先,你需要使用equals而不是冒号。

grant_type=client_credentials 

这是example POST from the RFC

POST /token HTTP/1.1 
Host: server.example.com 
Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW 
Content-Type: application/x-www-form-urlencoded 

grant_type=client_credentials 
+0

由单个字符卡住30分钟,谢谢! –

相关问题