2,node-http

服务端:
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(){
 
})
原文地址:https://www.cnblogs.com/uh-huh/p/4433445.html