2012-03-14 125 views
1

I cannot display chinese character response to browser using nodejs ?Chinese character in nodejs response write

jsdom.env({ html: 'http://www.baidu.com', 
    scripts: ['http://code.jquery.com/jquery-1.6.min.js'] 
}, function (err, window) { 
    //Use jQuery just as in a regular HTML page 
    var $ = window.jQuery; 

    res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }); 
    res.end($('title').text()); 
}); 

Incorrect result : ٶ һ £ ֪

Correct result should be : 百度一下,你就知道

+0

Are you able to print to console correctly? – 2012-03-14 16:19:12

回答

2

因爲百度的網頁編碼是GBK的

because the charset of baidu.com is GBK

+0

Already set gb2312 or GBK still same. result : 錕劫訛拷一錕鉸o拷錕斤拷錕斤拷知錕斤拷 – user717166 2012-03-14 09:33:24

+0

I believe nodejs only supports UTF8. Check the source. – 2012-03-14 16:20:36