【发布时间】:2017-08-05 05:34:13
【问题描述】:
当我使用 Postman 向 Spotify Swap 端点发出 HTTP POST 请求时,服务器给了我一个包含刷新令牌的正确响应,但我在使用我的 Java 应用程序访问端点时无法获得相同的响应。
当直接点击 Spotify 端点时,我让我的 Java 应用程序生成与通过 Postman 生成的请求相同的请求。当我侦听 TCP 连接时,我看不到两个请求之间的差异超过身份验证代码,无法重用。
使用 Postman 和 a_code 的请求如下所示:
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"}
【问题讨论】: