Tag: cjk

为什么我不能在nodejs HTTP响应中写中文字符?

这是我的小代码: var http = require('http'); var port = 9002; var host_ip = '<my_ip>'; http.createServer(function (req, res) { var content = new Buffer("Hello 世界", "utf-8") console.log('request arrived'); res.writeHead(200, { 'Content-Encoding':'utf-8', 'charset' : 'utf-8', 'Content-Length': content.length, 'Content-Type': 'text/plain'}); res.end(content.toString('utf-8'),'utf-8'); }).listen(port, host_ip); console.log('server running at http://' + host_ip + ':' + port); 以前我只是让res.end发送“你好世界”,它运作良好。 然后我想稍微调整一下,把“世界”改成中文的“世界”,把标题中的“charset”内容types改为“utf-8”。 但在Chrome和Firefox中,我看到了这一点: hello 涓栫晫 然而,惊人的歌剧(11.61)确实显示了正确的结果hello […]