简体   繁体   English

nodejs响应中的汉字写法

[英]Chinese character in nodejs response write

I cannot display chinese character response to browser using nodejs ? 我无法使用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 : 百度一下,你就知道 正确的结果应该是:百度一下,你就知道

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

because the charset of baidu.com is GBK 因为baidu.com的字符集是GBK

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM