var http = require("http");//负责创建web服务器,处理http相关任务 fs = require('fs');function load_album_list (callback){ console.log(2); fs.readdir( 'img','utf-8',function(err,files){ if(err){ callback(err); return; } callback(null,files); } );} function handle_incoming_request(req,res){ console.log(1); res.setCharacterEncoding("utf-8"); console.log("incoming request:" + req.method+ "" +req.url); load_album_list(function(err,albums){ if(err){ res.writeHead(503,{"Content-Type":"application/json;charset=utf-8"}); res.end(JSON.stringify(err) + "\n"); return; } var out = { error:null, data:{albums:albums} }; res.writeHead(200,{"Content-Type":"application/json"}); res.end("封测人"+JSON.stringify(out) + "\n"); }); }var s = http.createServer(handle_incoming_request);s.listen(3000);
1 回答
已采纳
叠加无限
TA贡献1条经验 获得超0个赞
res.end("封测人"+JSON.stringify(out) + "\n");
你这里输出的只是html的body里的内容,没有设置<meta charset="utf-8">,改成
res.end('<!DOCTYPE html><html><head><meta charset="UTF-8"></head><body>'+JSON.stringify(out)+'</body></html>')
- 1 回答
- 0 关注
- 2184 浏览
添加回答
举报
0/150
提交
取消