我的代码有什么问题。我正在发出 curl post 请求,但数据未显示在 header 的响应 body 中

What's problem with my code. I am giving a curl post request but data is not showing in respose body of header

此代码正在从 curl 接收数据,并假设在 header body 响应中显示该数据。但它不起作用。我哪里错了???

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();
});

});

如果您要在响应正文中设置 All together now!,这应该可以完成工作。

const http = require('http');

const server = http.createServer((req, res) => {
    let body = [];
    req.on('error', (err) => {
        console.error(err);
    })
    req.on('data', (chunk) => {
        body.push(chunk);
    })
    req.on('end', () => {
        body = Buffer.concat(body).toString();

        // set response
        res.writeHead(200, { 'Content-Type': 'text/plain' });
        res.end(body);
    });
});

server.listen('3000');