【问题标题】:Post using multipart/form-data with bent in node.js在 node.js 中使用带有弯曲的 multipart/form-data 发布
【发布时间】:2021-09-17 07:42:47
【问题描述】:

我正在尝试在 node.js 中使用 bentPOST,我已经能够使用以下代码发布 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);

【问题讨论】:

    标签: node.js curl post


    【解决方案1】:

    解决了这个问题,正确的表单标题没有传递给弯曲,所以我不得不重写如下

    return await post('http://localhost/endpoint', form, form.getHeaders());
    

    【讨论】:

      猜你喜欢
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多