站长资源
中国站长网站

node.js中的http.response.end方法使用说明

方法说明:

结束响应,告诉客户端所有消息已经发送。当所有要返回的内容发送完毕时,该函数必须被调用一次。

如何不调用该函数,客户端将永远处于等待状态。

语法:

response.end([data], [encoding])

接收参数:

data //end()执行完毕后要输出的字符,如果指定了 data 的值,那就意味着在执行完 response.end() 之后,会接着执行一条 response.write(data , encoding);

encoding //对应data的字符编码

例子:

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

');
}).listen(3000);

本文出处:来自互联网信息共享,请勿相信收费信息站长资源 » node.js中的http.response.end方法使用说明

评论 抢沙发

评论前必须登录!