【发布时间】:2021-09-17 07:42:47
【问题描述】:
我正在尝试在 node.js 中使用 bent 到 POST,我已经能够使用以下代码发布 application/json 并在另一端收到数据。
const bent = require('bent');
const postJSON = bent('POST', 'json', { 'Content-Type': 'application/json'});
const field = 'data';
return await postJSON('http://localhost/endpoint', { field });
但是,当我使用以下代码执行multipart/form-data 时,没有发生错误,但我在另一端没有收到任何数据。
var FormData = require('form-data');
var form = new FormData();
form.append('my_field', 'my value');
form.append('my_buffer', 'my data');
const bent = require('bent');
//const postJSON = bent('POST', 'string', { 'Content-Type': 'multipart/form-data'});
const postJSON = bent('POST', 'buffer', { 'Content-Type': 'multipart/form-data'});
return await postJSON('http://localhost/endpoint', form);
【问题讨论】: