【发布时间】:2021-09-05 11:43:13
【问题描述】:
由于轻量级,我正在使用 vscode 的 REST 客户端扩展而不是邮递员,但是当我尝试发送 POST 请求时,它似乎没有发送 JSON 数据。它在邮递员和 reqbin 上运行良好,但不适用于 REST 客户端,我只收到空正文。
这里是请求网址
@hostname-tour = http://localhost:3000/api/v1/tours
POST {{hostname-tour}} HTTP/1.1
Content-Type: "application/json"
{
"name": "Test Tour",
"duration": "10",
"diffculty": "easy"
}
这是后端代码
const express = require("express");
const app = express();
app.use(express.json());
app.post("/api/v1/tours", (req, res) => {
console.log(req.body);
res.status(200).json({
received: req.body,
});
});
let port = 3000;
app.listen(port, () => {
console.log("Listening at port: ", port);
});
【问题讨论】:
标签: node.js json visual-studio-code http-post