如何在NodeJS中传递axios POST请求中的文本/纯文本内容 [英] How to pass text/plain content in axios POST request in nodejs
本文介绍了如何在NodeJS中传递axios POST请求中的文本/纯文本内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在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);
});
};
为此,我如何正确传递正文参数?
推荐答案
var config = {
headers: {
'Content-Length': 0,
'Content-Type': 'text/plain'
},
responseType: 'text'
};
responseType
表示服务器将使用的数据类型 回复- 选项包括arrayBuffer、BLOB、DOCUMENT、JSON、Text、STREAM
这篇关于如何在NodeJS中传递axios POST请求中的文本/纯文本内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文