const http = require("http");
var postData = "{}";
let currentTime = Date.now(); //获取当前时间
let tokenId = window.localStorage.getItem("TokenId");
var options = {
hostname: "117.78.51.252",
port: 8030,
path: "/Ae/Resources/Download",
method: "POST",
headers: {
token: tokenId,
timestamp: currentTime,
nonce: "", //设备唯一标识UUID
signature: "", //当前请求内容的数字签名
"Content-Type": "application/octet-stream"
}
};
var bufs = [];
var req = http.request(options, res => {
let commonPath = path.join(this.rootPath, "AeUser", "baseconfig/a.zip");
res.on("data", chunk => {
bufs.push(chunk);
});
res.on("end", () => {
var buf = Buffer.concat(bufs);
console.log("数据长度",buf.length)
fileFs.write(commonPath, buf).then(
res => {
console.log("111111");
},
err => {
console.log("22222", err);
}
);
});
});
req.on("error", e => {
console.error(`请求遇到问题: ${e.message}`);
});
// 写入数据到请求主体
req.write(postData);
req.end();
网友评论