Skip to content

Instantly share code, notes, and snippets.

@kjunichi
Created April 15, 2015 01:26
Show Gist options
  • Save kjunichi/3bc307e7eb66f638640c to your computer and use it in GitHub Desktop.
Save kjunichi/3bc307e7eb66f638640c to your computer and use it in GitHub Desktop.
https通信をHTTP Proxy経由でおこない、SJISなページを文字化けさせずにSJISエンコードでファイルに保存する
var fs = require('fs');
var tunnel = require('tunnel');
var tunnelAg = tunnel.httpsOverHttp({
proxy: {
host: '192.168.0.1',
port: 8080
}
});
var https = require('https');
options = {
host: 'www.google.co.jp',
port: 443,
path: '/',
agent: tunnelAg
};
https.get(options, function (res) {
var hdr = res.headers;
//hdr[];
console.log('HEADERS: ' + JSON.stringify(res.headers));
//res.setEncoding('utf8');
var length = 0;
var content=new Buffer([]);
res.on('data', function (chunk) {
//console.log(chunk.toString());
content = Buffer.concat([content,chunk]);
});
res.on('end', function() {
console.log(content.toString("binary"));
fs.writeFileSync("dump00.txt",content,{encoding:null});
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment