码迷,mamicode.com
首页 > Web开发 > 详细

2,node-http

时间:2015-04-16 23:38:29      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

服务端:
var http=require(‘http‘);

http.createServer(function(req,res){//创建web服务器对象
     
     res.writeHead(200,{//给服务器增加头
          ‘content-type‘ : ‘text/plain‘
     });
 
     res.writeHead(301,{//给服务器增加头-重定向
          ‘Location‘ : ‘http://www.nodejs.com/‘
     });
 
     res.end();
 
}).listen(88,"127.0.0.1")//定义服务器的端口及主机
 
 
url.parse(requestUrlStr).hostname  //主机名
url.parse(requestUrlStr).port  //端口
url.parse(requestUrlStr).pathname  //路径名
var http=require(‘http‘);
var options={
     host:"nodejs.com",
     port:88,
     path:‘/‘
}
 
http.get(options,function(res){
 
}).on(‘err‘,function(){
 
})

2,node-http

标签:

原文地址:http://www.cnblogs.com/uh-huh/p/4433445.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!