且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Express.js上使用Axios向Spotify API发出POST请求时出现错误400

更新时间:2022-05-03 07:05:44

来自axios文档:By default, axios serializes JavaScript objects to JSON. To send data in the application/x-www-form-urlencoded format instead, you can use one of the following options.

对于Nodejs,您可以使用 querystring 模块,如下所示:

For Nodejs you can use the querystring module as follows:

var querystring = require('querystring');
axios.post('http://something.com/', querystring.stringify({ foo: 'bar' }));

因此,您可以尝试data: querystring.stringify({ grant_type: 'client_credentials' })