如何在Node.js中使用zip文件发出http放置请求

问题描述:

我想用二进制文件向网络api发送带有zip文件的http PUT请求,并获取带有http状态代码的响应.

I want to make a http PUT request with zip file in binary to a web api and get response with http status code.

如何读取文件并将其放入二进制文件中?

How to read the file and PUT it with binary ?

谢谢您的帮助!

您可以从以下内容开始:

You can start with this:

var http = require('http');
var fs   = require('fs');

var req = http.request({
  hostname : HOSTNAME,
  port     : PORT,
  path     : UPLOAD_PATH,
  method   : 'PUT',
});

fs.createReadStream('somefile.zip').pipe(req);

您可能需要执行其他一些操作,例如正确的错误处理,设置Content-Type标头等.

You may need to perform some other actions, like proper error handling, setting Content-Type headers, etc.