该方法的文档写入, “如果指定了数据,则相当于在响应之后调用response.write(data,encoding)。结束()。”Node.js response.end([data],[encoding])方法
与DOC描述了回复于(组块,[编码])为,
块可以是一个字符串或缓冲剂。如果chunk是一个字符串,则第二个参数指定如何将其编码为字节流。默认情况下,编码是'utf8'。
我仍然没有得到如何使用这种方法给出的描述。在这种情况下,有人可以给出一组工作参数的一个非常简单的例子吗?
该方法的文档写入, “如果指定了数据,则相当于在响应之后调用response.write(data,encoding)。结束()。”Node.js response.end([data],[encoding])方法
与DOC描述了回复于(组块,[编码])为,
块可以是一个字符串或缓冲剂。如果chunk是一个字符串,则第二个参数指定如何将其编码为字节流。默认情况下,编码是'utf8'。
我仍然没有得到如何使用这种方法给出的描述。在这种情况下,有人可以给出一组工作参数的一个非常简单的例子吗?
response.end(data, encoding)
将执行以下操作:
response.write(data, encoding);
response.end();
示例代码:
var http = require('http');
var server = http.createServer(function (request, response) {
response.writeHead(200, { "Content-Type": "text/plain" });
// 1st way
response.write('Hello World\n');
response.end();
// 2nd way, equivalent
//response.end('Hello World\n');
});
server.listen(8000);
console.log('running');
HM,简单:
res.write('<h1>It works!</h1>', 'utf8');
res.end();
相当于
res.end('<h1>It works!</h1>', 'utf8');