![](/img/trans.png)
[英]node.js, express, how to get data from body form-data in post request
[英]How to pipe stream data from file to the post body request in node js
我想使用pipe
將可讀流傳遞到發布請求主體,但是遇到了麻煩。 這是我的代碼:
var request = require('request');
var fs = require('fs');
var source = fs.createReadStream('./originalJsonDataWithObject.json'); //creating a read stream to read the file
source.pipe(request.post('http://localhost:3030/decompress')); //piping it to the post request
var request = require('request');
var fs = require('fs');
var file = fs.createReadStream('./originalJsonDataWithObject.json');
var req = request.post({
url: 'your post url',
headers: {<headers>},
body: file
});
POST請求正文參數是您隨請求實際發送的數據。 該數據可以采用多種形式(流,緩沖區,字符串等)。您無需通過管道傳輸數據。 如果您需要發布JSON數據,則可以執行以下操作:
const req = request.post({
url: 'http://localhost:3030/decompress',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(<your JSON data>)
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.