当 /api /token -java时,Spotify“意外状态:400”



当我提出http Post请求以使用Postman进行Spotify交换端点时,服务器给我一个包含刷新令牌的响应,但是在达到端点时,我无法获得相同的响应使用我的Java应用。

我使我的Java应用程序与Postman直接击中Spotify端点时生成的请求相同。当我收听TCP连接时,我不会看到两个请求之间的区别比Auth Code更不可重用。

使用a_code使用Postman的请求如下:

    bash-3.2$ nc -l 127.0.0.1 1234
    POST /api/token HTTP/1.1
    Host: localhost:1234
    Connection: keep-alive
    Content-Length: 460
    Accept: */*
    Cache-Control: no-cache
    Origin: chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop
    Authorization: Basic <base64 encoded client_id:client_secret>
    Content-Type: application/x-www-form-urlencoded
    User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
    Postman-Token: b089ac57-7dcd-f94a-f315-9f28f74ac9eb
    Accept-Encoding: gzip, deflate, br
    Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
code=a_code&grant_type=authorization_code&redirect_uri=my-spotifyoauth%3A%2F%2Fspotifylogincallback%2Ffree

使用我的Java应用程序的请求与another_code update ):

POST /api/token HTTP/1.1
Authorization: Basic <base64 encoded client_id:client_secret>
Accept: */*
Connection: keep-alive
Cache-Control: no-cache
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
Content-Length: 460
Host: localhost:1234
User-Agent: Apache-HttpClient/4.3.5 (java 1.5)
code=another_code&grant_type=authorization_code&redirect_uri=my-spotifyoauth%3A%2F%2Fspotifylogincallback%2Ffree

当我将端点从 localhost:1234切换到 accounts.spotify.com时,非假伪造时,我从服务器中得到了400个响应,我无法弄清楚为什么。

POST https://accounts.spotify.com/api/token responded with status 400
> Accept-Encoding: gzip
< Server: nginx
< Date: Tue, 14 Mar 2017 17:08:34 GMT
< Content-Type: application/json
< Content-Length: 69
< Connection: keep-alive
< Keep-Alive: timeout=600
< {"error":"server_error","error_description":"Unexpected status: 400"}

您知道为什么,即使在TCP上看到相同的请求,Spotify服务器响应也不同吗?我该如何进一步调试此问题?

更新:代码无法重复使用,因此每次提出新请求时,它们都应该与众不同。我的终点是使我通过它发送的任何代码无效。我第二次使用相同的代码达到终点,我会发现错误: {"error":"invalid_grant","error_description":"Invalid authorization code"}

我认为魔鬼在细节中。上面的请求肯定来自Postman,看到它具有邮递员的标题。如果您发布了Java应用程序发送给NetCat的内容,我们可以弄清楚。

我可以使用上面的示例重新创建请求,并且对我有用,而是看到了更具描述性的错误消息:

HTTP/1.1 400 Bad Request
{"error":"invalid_grant","error_description":"Authorization code expired"}

这也意味着您需要丢弃该帐户或更改客户端_secret,因为您将其发布到Stackoverflow,但我想您已经知道。

最新更新