如何在Node.js中使用zip文件发出http放置请求 [英] How to make http put request with zip file in nodejs
本文介绍了如何在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.
这篇关于如何在Node.js中使用zip文件发出http放置请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文