如何在nodejs中的axios POST请求中传递文本/纯内容

Mru*_*ker 7 node.js axios

我想传递身体参数,如屏幕截图所示 这里文本/纯格式

我在 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)

为此,我如何适当地传递身体参数?

Raj*_*nan 9

var config = {
    headers: {
        'Content-Length': 0,
        'Content-Type': 'text/plain'
    },
   responseType: 'text'
};
Run Code Online (Sandbox Code Playgroud)
  1. responseType 表示服务器将响应的数据类型
  2. 选项是 arraybuffer , blob , document, json , text, stream