鍍金池/ 問(wèn)答/HTML/ node頁(yè)面中文亂碼

node頁(yè)面中文亂碼

var http = require('http');
http.createServer(function (req,res) {
    res.writeHead(200,{'Content-Type':'text/html,charset=utf-8'});
    res.end('abc你好世界!','utf-8');
}).listen(8081);

打開網(wǎng)頁(yè)http://localhost:8081/后,顯示abc浣犲ソ涓栫晫錛?,為什么設(shè)置了響應(yīng)頭charset=utf-8還不能正常顯示呢?

回答
編輯回答
有點(diǎn)壞

你的頭信息設(shè)置錯(cuò)了應(yīng)該是:
res.writeHead(200,{'Content-Type':'text/html;charset=utf-8'});

中間是分號(hào):; 不是逗號(hào)

2017年9月27日 14:04