var http = require(‘http’); var querystring = require(‘querystring’); var server = http.createServer(function(req, res) { var post = '’; req.on('data’, function(chunk) { post += chunk; }); req.on('end’, function() { post = querystring.parse(post); console.log(text); res.write(post.title); res.write(post.text); res.end(); }); }).listen(3000);
改了以后还是不行……
<!DOCTYPE> <html> <head> <meta charset='tuf-8'> <title>Change</title> <style type="text/css"> </style> <script type="text/javascript"> </script> </head> <body> <form method="post" action="http://localhost:3000/"> <input type="text" name="title" /> <textarea name="text"></textarea> <input type="submit" /> </form> </form> </body> </html>var http = require(‘http’); var querystring = require(‘querystring’); var server = http.createServer(function(req, res) { var post = '’; req.on('data’, function(chunk) { post += chunk; }); req.on('end’, function() { post = querystring.parse(post); res.writeHead(200,{"Content-Type":"text/html;charset:UTF-8"}); res.write(post.title); res.write(post.text); res.end(); }); }).listen(3000);
好像编译没通过
@ggaaooppeenngg <meta charset='tuf-8'>
这写错了,是utf-8。text/html;charset:UTF-8
也错了,是text/html;charset=UTF-8
。楼主另外一篇post什么的没内容呀,乱码呀,就这个原因。