2017-07-26 54 views
1

我想通過身體參數Axios公司POST請求text/plain的內容顯示在屏幕截圖here在text/plain的格式如何通過在的NodeJS

我用我的NodeJS /快遞愛可信項目。我的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); 
     }); 
}; 

爲此,我該如何正確傳遞正文參數?

+0

到底是什麼問題?這看起來好像沒什麼問題 – lumio

+0

我想通過'{ 「請求」: 「/ V1 /順序/新」, 「現時」:123457, 「client_order_id」: 「20150102-4738721」, 「符號」: 「btcusd」, 「amount」:「34.12」, 「price」:「622.13」, 「side」:「buy」, 「type」:「exchange limit」 }'作爲身體參數,我將如何去做? –

+0

而不是'{firstName:'...'}'你使用剛發佈的那個對象? – lumio

回答

1
var config = { 
    headers: { 
     'Content-Length': 0, 
     'Content-Type': 'text/plain' 
    }, 
    responseType: 'text' 
}; 
  1. responseType表示數據的服務器將 與
  2. 選項響應類型是arraybuffer,一滴,文檔,JSON,文本,流