ndoe.js is Shift_JIS Encoding Support?

已查看 478 次
跳至第一个未读帖子

monkichi

未读,
2010年10月10日 13:53:012010/10/10
收件人 nodejs
Hi!Guys!

I'm Japanese User.
I acquire a Web page described in "Shift_JIS", and a garbage occurs
when I display it.

Is there any good idea?

Source is Follow:

var bbsmenu = new Buffer(1024);
var http = require('http');
var ch = http.createClient(80,'menu.2ch.net');
var request = ch.request('GET', '/bbstable.html',
{'host': 'menu.2ch.net',
'User-Agent':'node.js httpClient',
'Accept-Language': 'ja,en-us;q=0.7,en;q=0.3',
'Accept-Encoding': '',
'Accept-Charset': 'Shift_JIS,utf-8;q=0.7,*;q=0.7'}
);
request.end();
request.on('response', function (response) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
response.setEncoding('utf8');
response.on('data', function (chunk) {
bbsmenu = bbsmenu + chunk;
});

response.on('end', function () {
console.log(bbsmenu);
});

});

Ben Noordhuis

未读,
2010年10月10日 17:20:272010/10/10
收件人 nod...@googlegroups.com
Use node-iconv[1] to recode the content to UTF-8 (the encoding nodejs
and V8 use internally). You don't need to call response.setEncoding()
then, by the way.

[1] http://github.com/bnoordhuis/node-iconv

回复全部
回复作者
转发
0 个新帖子