node.js中http.respone.end方法概述

方法说明:

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

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

语法:

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

接收参数:

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

encoding:对应data的字符编码

例子:

1 var http=require('http');
2 var proxy=http.createServer(function(req,res){
3     res.writeHead('200',{'Content-Type':'text/plain'});
4     res.end('hello\n');
5 
6 });
7 proxy.listen('2000','127.0.0.1');

 

posted @ 2015-10-15 15:12  615  阅读(213)  评论(0编辑  收藏  举报