此代码正在从 curl 接收数据,并假设在标头正文响应中显示该数据。但它不起作用。我哪里错了???
const server = http.createServer((req , res) => {
res.writeHead(200, {'Content-type': 'text/plain'});
const { headers, method, url } = req;
let body = [];
req.on('error', (err) => {
console.error(err);
})
req.on('data', (chunk) => {
body.push(chunk);
})
req.on('end', () => {
body = Buffer.concat(body).toString();
});
});