如何在nodejs中的axios POST请求中传递text/plain内容

How to pass text/plain content in axios POST request in nodejs

我想传递正文参数,如屏幕截图所示 text/plain 格式

我在 nodejs/express 项目中使用 axios。我的reqeust格式如下图:

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);
        });
};

为此,我该如何适当地传递正文参数?

var config = {
    headers: {
        'Content-Length': 0,
        'Content-Type': 'text/plain'
    },
   responseType: 'text'
};
  1. responseType表示服务器将要处理的数据类型 回复
  2. 选项有 arraybuffer、blob、文档、json、文本、流