通过post抓取的页面数据 为啥不能展现在页面上 财富值4

2016-10-16 12:13发布

这是node.js代码

var http = require("http"),     fs = require("fs"),     querystring = require("querystring"),     url = require("url");  http.createServer(function(req,res){     var postdata="";     var query="what";     var pathname = url.parse(req.url).pathname;      req.setEncoding("utf8");     if(pathname=="/"){         var indexPage = fs.readFileSync("表单.html");         res.writeHead(200,{"Content-Type":"text/html"});         res.end(indexPage);     }     if(pathname=="/about"){         req.on("data",function(chunk){             postdata += chunk;         });         req.on("end",function() {             console.log(postdata);             query = querystring.parse(postdata);             console.log(query);         });         res.writeHead(200, {"Content-Type":"text/plain"});         console.log(query.Name);         console.log(query.number);         res.write(query.number+ "and "+query.number);         res.end();     }     else{         res.writeHead(404,{"Content-Type":"text/plain"});         res.end("Can not find the source");     } }).listen(2000,"127.0.0.1");  console.log("The server is running at port 2000");  这是html代码  <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <title>表单填写</title> </head> <body> <form action="/about" method="post">   <p> Name: <input type="text" name="Name"></p>     <p>SchoolNumber:<input type="text" name="number"></p>     <p><input type="submit" value="提交"></p> </form> </body> </html>  执行结果图: 

求大神解决 小弟感激不尽

友情提示: 问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
0条回答

一周热门 更多>