接收表单

get

//接收get表单的提交 var http = require("http"); var url = require("url"); http.createServer(function(req,res){ res.writeHead(200,{ 'Content-type':"text/html;charset=utf-8" }) //这里要设置要不然乱码 var queryString = url.parse(req.url,true).query; var title = queryString.title; var age = queryString.age; var sex = queryString.sex; res.end(title+age+sex); }).listen(8080);

post




    
    
    
    Document


    



篮球 足球 羽毛球
var http =require("http"); var querystring =require("querystring"); var util =require("util") var server=http.createServer(function(req,res){ if(req.url=="/doPost"){ var postData=""; req.on("data",function(chunk){ postData+=chunk; }) req.on("end",function(){ //console.log(postData); var param=querystring.parse(postData); res.writeHead(200,{"Content-type":"text/html;charset=utf8"}); res.end(param.title+" "+param.age+" "+param.sex+" "+param.bobby.length); }) } }) server.listen(8080);

你可能感兴趣的:(接收表单)