Get获取内容:
var http=require('http'),
util=require('util'),//util 提供常用函数集合
url=require('url'); http.createServer(function(req,res){ res.writeHead(200,{'Content-Type':'text/html;charset=utf-8'}); var params=url.parse(req.url,true).query; res.write('www'+params.name); res.end(); }).listen(8000)
post获取内容
var querystring=require('querystring'); var postHTML=`<html><title>post</title><body><form method='post'> 名字:<input type='text' name='name' value='bin'> 年龄:<input type='text' name='age' value='30'> 提交:<input type='submit'></form> </body></html>` http.createServer(function(req,res){ var post=''; req.on('data',function(chuck){ post+=chuck }); req.on('end',function(){ res.writeHead(200,{'Content-Type':'text/html;charset=utf-8'}); post=querystring.parse(post); if(post.name&&post.age){ res.write('name:'+post.name); res.write('age:'+post.age); }else{ res.write(postHTML) } res.end() }) }).listen(3000)