Node.js Node js 5.5.0-发布表单后未引发请求对象上的数据
我尝试下面的代码一切工作正常,除了“数据”事件没有被提出,由于这一点,我无法收集张贴的表单数据Node.js Node js 5.5.0-发布表单后未引发请求对象上的数据,node.js,Node.js,我尝试下面的代码一切工作正常,除了“数据”事件没有被提出,由于这一点,我无法收集张贴的表单数据 var http = require("http"); var fs = require("fs"); http.createServer(function(req,res){ if (req.method === "GET") { res.writeHead(200, {"Content-Type":"text/html"}); fs.creat
var http = require("http");
var fs = require("fs");
http.createServer(function(req,res){
if (req.method === "GET")
{
res.writeHead(200, {"Content-Type":"text/html"});
fs.createReadStream("./public/form.html","UTF-8").pipe(res);
}
if (req.method === "POST")
{
var body = "";
console.log("post received.");
**req.on("data",function(){**
var chunk="";
console.log("chunk started");
body +=chunk;
});
req.on("end", function(){
console.log("end started");
res.writeHead(200, {"Content-Type":"text/html"});
res.end(`<!DOCTYPE html>
<html>
<head>
<title>Form Results</title>
</head>
<body>
<h1>Your form Results:</h1>
<p>${body}</p>
</body>
</html>`);
});
}
}).listen(3000);
console.log("FormServer is running on port 3000");
var http=require(“http”);
var fs=要求(“fs”);
http.createServer(函数(req,res){
如果(请求方法==“获取”)
{
res.writeHead(200,{“内容类型”:“text/html”});
fs.createReadStream(“./public/form.html”,“UTF-8”).pipe(res);
}
如果(请求方法==“POST”)
{
var body=“”;
console.log(“post-received”);
**请求打开(“数据”,函数(){**
var chunk=“”;
log(“块启动”);
body+=块;
});
请求开启(“结束”,函数(){
console.log(“结束启动”);
res.writeHead(200,{“内容类型”:“text/html”});
res.end(`
表格结果
您的表格结果:
${body}
`);
});
}
}).听(3000);
log(“FormServer正在端口3000上运行”);
提前感谢它对我有效,你确定你发送的数据正确吗?是的,它现在也对我有效。不确定代码出了什么问题,我没有做任何更改,工作正常。它花了太多的时间,甚至没有修好。无论如何,谢谢你的回答,谢谢。