問題
相關
解壓回應
根據關于如何解壓縮(解壓縮)NodeJS 請求的模塊 gzip 回應正文的答案?,你可以這樣解壓:
var http = require("http"),
zlib = require("zlib");
function getGzipped(url, callback) {
// buffer to store the streamed decompression
var buffer = [];
http.get(url, function(res) {
// pipe the response into the gunzip to decompress
var gunzip = zlib.createGunzip();
res.pipe(gunzip);
gunzip.on('data', function(data) {
// decompression chunk ready, add it to the buffer
buffer.push(data.toString())
}).on("end", function() {
// response and decompression complete, join the buffer and return
callback(null, buffer.join(""));
}).on("error", function(e) {
callback(e);
})
}).on('error', function(e) {
callback(e)
});
}
getGzipped(url, function(err, data) {
console.log(data);
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/368084.html
標籤:javascript 节点.js 打字稿 http-headers 堆栈交换-api
