Created
April 15, 2015 01:26
-
-
Save kjunichi/3bc307e7eb66f638640c to your computer and use it in GitHub Desktop.
https通信をHTTP Proxy経由でおこない、SJISなページを文字化けさせずにSJISエンコードでファイルに保存する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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