http.response.write方法使用说明

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

res.writeHead(200, {'Content-type' : 'text/html'});
res.write('<script>');
res.write('window.parent.postMessage("'+fname+'","*");');
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);
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容