NodeJs Express:无法发布请求

时间:2020-03-31 06:13:27

标签: node.js express

我无法发布请求。我确保将urlencoded设置为false。

当我尝试使用参数发布时,最终在网页中显示“ Cannot GET .....”。

不确定为什么。

app.use(express.urlencoded({ extended: false }));

app.post("/task-create/title/:title/description/:description/start/:start/end/:end/priority/:priority/category/:category/status/:status", async (req, res) => {

  const task = new Task(
    { 
      title: req.body.title,
      description: req.body.description,
      start: req.body.start,
      end: req.body.end,
      priority: req.body.priority,
      category: req.body.category,
      status: req.body.status
    });

  await task.save().then(() => console.log("Task created"));

  res.send("Task created \n");
});

1 个答案:

答案 0 :(得分:3)

您必须使用rest客户端来测试该端点并为其分配post方法,而不是直接从浏览器中进行分配。您可以使用InsomniaPostman

相关问题