axios
http
ライブラリを使用するために変換しようとしている小さな Spotify アプリがあります。ログイン時のコールバックに問題があります。これまで、すべてのドキュメントrequest
で like is を使用してきました。Spotify
すべてが で正常に動作しrequest
ますが、すべてが で同じように見えますがaxios
、500 Internal Server Error
. http
リクエストを行うための私のコードは次のとおりです。
var authOptions = {
method: 'POST',
url: 'https://accounts.spotify.com/api/token',
form: {
code: code,
redirect_uri: REDIRECT_URI,
grant_type: 'authorization_code'
},
headers: {
'Authorization': 'Basic ' + (new Buffer(CLIENT_ID + ':' + CLIENT_SECRET).toString('base64'))
},
json: true
};
axios(authOptions).then(res => {
console.log(res)
})
authOptions
同じオブジェクトをrequest
ライブラリに渡すことができ、すべて正常に動作します。axios
コンソールにログアウトしてからの私のリクエストは次のとおりです。
{
method: 'POST',
url: 'https://accounts.spotify.com/api/token',
form:
{ code: 'changedthecode',
redirect_uri: 'http://localhost:8888/callback',
grant_type: 'authorization_code' },
headers: { Authorization: 'Basic changedthecode=' },
json: true,
timeout: 0,
transformRequest: [ [Function] ],
transformResponse: [ [Function] ],
withCredentials: undefined
}
そして、これがaxios
ライブラリに対する私の応答です。
{ data: { error: 'server_error' },
status: 500,
statusText: 'Internal Server Error',
headers:
{ server: 'nginx',
date: 'Fri, 04 Dec 2015 14:48:06 GMT',
'content-type': 'application/json',
'content-length': '24',
connection: 'close' },
config:
{ method: 'POST',
headers: { Authorization: 'Basic changedthecode' },
timeout: 0,
transformRequest: [ [Function] ],
transformResponse: [ [Function] ],
url: 'https://accounts.spotify.com/api/token',
form:
{ code: 'changedthecode',
redirect_uri: 'http://localhost:8888/callback',
grant_type: 'authorization_code' },
json: true,
withCredentials: undefined }
}
from について私が知らなかった唯一のオプションaxios
は、またはwithCredentials
に設定されている場合は機能しませんでした。他に何が欠けていますか?false
true