[英]req.on is not getting trigger while using type application/json
req.on("data", (chunk) => {
console.log("daataa second",body)
body += chunk.toString();
});
When i am posting the data from the postman as the type then it successfully processing the data but when i am passing the data in json format then it is not triggering this method.当我将邮递员的数据作为类型发布时,它会成功处理数据,但是当我以 json 格式传递数据时,它不会触发此方法。
If i use json middleware, then none of the data or end event on request object is fired but I removed the json parser from your code, and then the events started firing如果我使用 json 中间件,则不会触发请求对象上的任何数据或结束事件,但我从您的代码中删除了 json 解析器,然后事件开始触发
JSON parser middleware reads the entire request stream containing a JSON payload, parses it and creates a JavaScript object for you. JSON 解析器中间件读取包含 JSON 有效负载的整个请求流,对其进行解析并为您创建一个 JavaScript 对象。 For example in Express, express.json returns middleware that reads and saves JSON payloads as the
req.body
object if the request contains JSON data例如在 Express 中,如果请求包含 JSON 数据, express.json返回读取 JSON 有效负载并将其保存为
req.body
对象的中间件
JSON middleware needs to read the entire request stream in order to parse its content using JSON.parse(string)
, and so will not call next
to invoke further steps in request routing before the stream has been read and parsed. JSON 中间件需要读取整个请求流才能使用
JSON.parse(string)
解析其内容,因此在读取和解析流之前不会调用next
来调用请求路由中的进一步步骤。 Hence listeners added later in the route to monitor data
and/or end
events will not fire because the data has already been read, and the end
event has already fired.因此,稍后在路由中添加的侦听器以监视
data
和/或end
事件将不会触发,因为数据已经被读取,并且end
事件已经触发。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.