nodejs响应中的中文字符写入

时间:2012-03-14 08:54:38

标签: javascript jquery node.js jsdom

我无法使用nodejs向浏览器显示中文字符响应?

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());
});

结果不正确: وٴ ٴ £ ֪

正确的结果应该是:百度一下,你就知道

1 个答案:

答案 0 :(得分:1)

因为百度的网页编码是GBK的

因为baidu.com的字符集是GBK