[英]How to response dynamic content in Nodejs without Express
let reqBody = "";
req
.on("data", (chunk) => {
reqBody += chunk.toString();
})
.on("end", () => {
const body = new URLSearchParams(reqBody);
res.end("ok");
});
I'm trying to access the request's body using NodeJS without Express but for some reason, I could not run res.end("ok");
我正在尝试使用没有 Express 的 NodeJS 访问请求的正文,但由于某种原因,我无法运行
res.end("ok");
. .
You need to call req.end()
as well您还需要调用
req.end()
check Node.js document https://nodejs.org/api/http.html检查 Node.js 文档https://nodejs.org/api/http.html
With http.request() one must always call req.end() to signify the end of the request - even if there is no data being written to the request body
使用 http.request() 必须始终调用 req.end() 来表示请求的结束 - 即使没有数据写入请求正文
let reqBody = "";
req
.on("data", (chunk) => {
reqBody += chunk.toString();
})
.on("end", () => {
const body = new URLSearchParams(reqBody);
res.end("ok");
});
req.end();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.