【问题标题】:Send http request using octet/stream via node.js通过 node.js 使用八位字节/流发送 http 请求
【发布时间】:2018-05-04 10:09:47
【问题描述】:

目前我的用例是我的node.js 服务器Server A 需要创建一个CSV 文件,然后将该CSV 发送到另一个服务器Server B,它只接受application/octet-stream

目前我正在手动将 csv 卷曲以将其上传到服务器 B。

curl -H "Content-Type:application/octet-stream" 
    -X PUT https://someexample.com/url/what/not 
    --upload-file newlyCreated.csv

但我需要自动执行上面的 curl 并想使用 node.js,因为服务器 A 是在 node.js 中构建的。我的直觉引导我使用流,但我似乎无法让它发挥作用。

fs.createReadStream('/path/to/csv').pipe(httpRequestToServerB)

然后响应客户端并发送一个成功的JSON

【问题讨论】:

    标签: node.js http stream httprequest octetstring


    【解决方案1】:

    目前,我使用request NPM 模块找到了我的问题的答案:

    fs.createReadStream('/path/to/csv').pipe(request.post('url').on('end', (done) => {
      console.log('Upload Done')
    }));
    
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2011-06-30
      • 1970-01-01
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-05-30
      相关资源
      最近更新 更多