此处{'Content-Type':'text / html'}的用途是什么?
var http = require('http');
var fs = require('fs');
http.createServer(function (req, res) {
fs.readFile('demofile.html', function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
});
}).listen(8080);
console.log("Listening at 8080...");`
答案 0 :(得分:-1)
答案 1 :(得分:-1)
当您要将数据发送回客户端时,可以将标头发送到该客户端。
'Content-Type': 'text/html
与这段代码的客户端将找出它将接收html文件。
您可以将json文件或html文件发送回clinet。
'Content-Type': 'text/html
===>这将显示您正在发送html输出
'Content-Type': 'application json
====>这将显示您正在发送json输出