【问题标题】:Perform POST from Browser URL从浏览器 URL 执行 POST
【发布时间】:2019-10-31 18:13:30
【问题描述】:

我有一个通过点击电子邮件中的链接来验证用户的功能。我在 Mongo User 集合中有字段,称为 Active。这是一个布尔值。当用户注册时,Active 将为 false。当他们单击链接时,活动将变为 true。我的问题是链接在邮递员中运行良好,但在浏览器 URL 中不起作用。

我的代码

  verify = (req, res) => {
    User.update({ email: req.query.mail }, { $set: { active: true } }, (err, user) => {
      if (err) {
        res.send(err);
      } else {
       res.send(user);
      }
    });
  } 

我的 API:POST api/user/verifySignin

我的链接:http://localhost:3000/api/user/verifySignin?mail=abc@xyz.com

我在浏览器 URL 中使用此链接它不起作用,但我在 POSTMAN 中使用它的工作。帮帮我,我哪里出错了

【问题讨论】:

    标签: node.js rest api post postman


    【解决方案1】:

    您不能直接在浏览器中从 URL 发出 post 请求,您需要使用 XMLHTTP 请求库(如 fetch)或使用 <form action="http://localhost:3000/api/user/verifySignin?mail=abc@xyz.com" method="post">

    【讨论】:

    【解决方案2】:
    1. 尝试 $http 传递 url

    $http.post(http://localhost:3000/api/user/verifySignin)

    【讨论】:

    • 请提供任何参考链接
    猜你喜欢
    • 2010-12-23
    • 2013-06-07
    • 1970-01-01
    • 2019-03-25
    • 2020-08-17
    • 1970-01-01
    • 1970-01-01
    • 2014-12-18
    相关资源
    最近更新 更多