我在 nodejs/express 项目中使用 axios。我的请求格式如下图:
var config = {
headers: {
'Content-Length': 0,
'Content-Type': 'text/plain'
}
};
const testInput = (req, res) => {
axios.post('https://api.sandbox.xyz.com/v1/order/new', { firstName: 'Marlon' }, config)
.then(function(response) {
console.log('saved successfully')
})
.catch(function(error) {
console.log(error);
});
};
Run Code Online (Sandbox Code Playgroud)
为此,我如何适当地传递身体参数?
var config = {
headers: {
'Content-Length': 0,
'Content-Type': 'text/plain'
},
responseType: 'text'
};
Run Code Online (Sandbox Code Playgroud)
responseType 表示服务器将响应的数据类型