【问题标题】:How to pass text/plain content in axios POST request in nodejs如何在nodejs中的axios POST请求中传递文本/纯内容
【发布时间】:2017-09-20 19:31:57
【问题描述】:

我想传递正文参数,如屏幕截图 所示(文本/纯格式

我在我的 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);
        });
};

为此,我怎样才能适当地传递正文参数?

【问题讨论】:

  • 到底是什么问题?我觉得很好
  • 我想将{ "request": "/v1/order/new", "nonce": 123457, "client_order_id": "20150102-4738721", "symbol": "btcusd", "amount": "34.12", "price": "622.13", "side": "buy", "type": "exchange limit" } 作为正文参数传递,我该怎么做?
  • 你使用刚刚发布的对象而不是{ firstName: '...' }

标签: node.js axios


【解决方案1】:
var config = {
    headers: {
        'Content-Length': 0,
        'Content-Type': 'text/plain'
    },
   responseType: 'text'
};
  1. responseType 表示服务器将要发送的数据类型 回复
  2. 选项有 arraybuffer、blob、document、json、text、stream

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-16
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 2017-11-20
    • 2021-12-16
    • 2020-05-11
    • 2019-03-25
    相关资源
    最近更新 更多