const fs = require('fs');
const qs = require('querystring');
require('http').createServer(function (req,res) {
if (req.url === '/'){
res.writeHead(200,{'content-type':'text/html'});
res.end(['<form method="post" action="/url">',
'<input type="text" name="name">',
'<input type="submit">',
'<button>Submit</button>', //
'</form>'].join(''))
}
else if ('/url' === req.url && req.method==='POST') {
res.writeHead(200,{'content-type':'text/plain'});
var body = '';
req.on('data',function (chunk) {
body += chunk;
});
console.log(body) //无输出
res.end('hello world' +qs.parse(body).name +' end')//输出undefined
}
}).listen(3000);
为什么在表单中输入数据后提交 无法被node获得,body变量无内容??
jeck猫
皈依舞
相关分类