http.response.write方法使用说明

发布时间:2018-12-02编辑:佚名阅读(1406)

向请求的客户端发送响应内容。在response.end()之前,response.write()可以被执行多次。

res.writeHead(200, {'Content-type' : 'text/html'});
res.write('<script>');
res.write('alert(1);');
res.end('</script>');

response.write(chunk, [encoding])
参数:chunk是一个buffer或字符串,表示发送的内容encoding如果chunk是字符串,就需要指定encoding来说明它的编码方式,默认utf-8。

var http = require('http');
http.createServer(function(req, res){
 res.writeHead(200, {'Content-type' : 'text/html'});
 res.write('<h1>Node.js</h1>');
 res.end('<p>Hello World</p>');
}).listen(3000);


  关键字:http.response.write方法使用说明


鼓掌

0

正能量

0

0

呵呵

0


评论区