Chinese character in nodejs response write

放肆的年华 提交于 2019-12-11 08:38:56

问题


I cannot display chinese character response to browser using 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());
});

Incorrect result : �ٶ�һ�£�����֪��

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


回答1:


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

because the charset of baidu.com is GBK



来源:https://stackoverflow.com/questions/9698552/chinese-character-in-nodejs-response-write

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!