小编Mub*_*Ali的帖子

其余客户端 vscode 扩展不发送 json 数据

由于轻量级,我使用 vscode 的 REST 客户端扩展而不是 postman,但当我尝试发送 POST 请求时,它似乎没有发送 JSON 数据。它在邮递员和 reqbin 上工作正常,但在 REST 客户端上则不然,我只收到空的正文。

这是请求 URL

@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"
}
Run Code Online (Sandbox Code Playgroud)

这是后端代码

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);
});
Run Code Online (Sandbox Code Playgroud)

使用 Postman 和 reqbin 一切正常 请求箱输出

但从 REST 客户端接收空对象 Rest 客户端扩展输出

json http-post node.js visual-studio-code

0
推荐指数
1
解决办法
4291
查看次数

标签 统计

http-post ×1

json ×1

node.js ×1

visual-studio-code ×1