【发布时间】:2020-09-06 09:51:03
【问题描述】:
此代码正在从 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();
});
});
【问题讨论】:
-
嗨,您能否添加
curl命令并添加有关您要激活的内容的更多信息? -
' curl --location --request POST 'localhost:3000' \ --header 'Content-Type: text/plain' \ --data-raw '现在都在一起了!' '
-
这是 curl 命令。我只想显示“现在都在一起!”通过此命令在标头正文响应中
-
header body response是什么意思?有一个由标头和正文构建的 HTTP 响应。你在哪里设置All together now!?
标签: node.js curl echo-server