var http = require("http");
var fs = require("fs");
var url=require("url");
var app=(req,res)=>{
var pathname = url.parse(req.url).pathname;
var method = req.method.toLowerCase();
if(pathname=="/favicon.ico")return;
if(pathname=="/"){
fs.readFile("./ajax.html",(err,data)=>{
res.writeHead(200,{‘content-type‘:‘text/html;charset=utf8‘});
res.end(data);
})
}
if(pathname=="/ss"&&method=="get"){
// console.log(url.parse(req.url).query);
res.writeHead(200,{‘content-type‘:‘text/html;charset=utf8‘});
res.end(‘{"data":"这是GET数据"}‘);
}
if(pathname=="/ss"&&method=="post"){
// console.log("sdsd");
req.on("data",function(data){
//打印
// console.log(decodeURIComponent(data));
});
res.writeHead(200,{‘content-type‘:‘text/html;charset=utf8‘});
res.end(‘{"data":"这是POST的数据"}‘);
}
console.log(url.parse(req.url))
}
http.createServer(app).listen(8000);