Request: cara unzip respons gzip

Dibuat pada 27 Des 2013  ·  6Komentar  ·  Sumber: request/request

Contoh:

function response (err, response, body) {

// current how to unzip body ?

}
request.get({
    url : path,
    headers: {
        'Accept-Encoding' : 'gzip'
    }
}, response);

Komentar yang paling membantu

@VRMink ini dia contohnya

  zlib = require('zlib');

function response (err, res, body) {
//check res header it is gzip
 console.log(res.headers['content-encoding'])
//now body it is gzip stream buffer
      zlib.unzip(body, function(err, buffer) {
             console.log(buffer.toString())
       }

}
    request.get({
        url : apiUrl,
        headers: {
            'Accept-Encoding' : 'gzip',
          },
        encoding : null  // it is very import!!
    }, response);



Semua 6 komentar

saya menyelesaikannya.

Bagaimana Anda menyelesaikannya?

@VRMink ini dia contohnya

  zlib = require('zlib');

function response (err, res, body) {
//check res header it is gzip
 console.log(res.headers['content-encoding'])
//now body it is gzip stream buffer
      zlib.unzip(body, function(err, buffer) {
             console.log(buffer.toString())
       }

}
    request.get({
        url : apiUrl,
        headers: {
            'Accept-Encoding' : 'gzip',
          },
        encoding : null  // it is very import!!
    }, response);



Terima kasih - itu tidak terlalu jelas :)

@youxiachai Terima kasih!

Terima kasih atas solusi Anda!

Apakah halaman ini membantu?
0 / 5 - 0 peringkat

Masalah terkait

Guymestef picture Guymestef  ·  3Komentar

mlegenhausen picture mlegenhausen  ·  4Komentar

crostine picture crostine  ·  3Komentar

Kue
ghost picture ghost  ·  3Komentar

codecowboy picture codecowboy  ·  3Komentar