当我发送节点请求其完全按预期方式工作时。但是,当我在axios中发送异步请求时,它会以415错误响应我。我猜可能转换为axios是错误的。
如何将其更改为axios请求?
var client_id = 'CLIENT_ID';
var client_secret = 'CLIENT_SECRET';
var authOptions = {
url: 'https://accounts.spotify.com/api/token',
headers: {
'Authorization': 'Basic ' + (Buffer.from(client_id + ':' + client_secret).toString('base64'))
},
form: {
grant_type: 'client_credentials'
},
json: true
};
request.post(authOptions, function(error, response, body) {
if (!error && response.statusCode === 200) {
var token = body.access_token;
console.log(token)
}
});