ndoe.js is Shift_JIS Encoding Support?

474 views
Skip to first unread message

monkichi

unread,
Oct 10, 2010, 1:53:01 PM10/10/10
to 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

unread,
Oct 10, 2010, 5:20:27 PM10/10/10
to 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

Reply all
Reply to author
Forward
0 new messages