【问题标题】:res.redirect(/logout) is sending a get request, how to make it so that it sends a post requestres.redirect(/logout) 正在发送一个get请求,如何使它发送一个post请求
【发布时间】:2021-10-26 10:17:04
【问题描述】:

我有一个在某些情况下使用重定向的函数

return res.redirect('/logout');

我使用

处理上述重定向
app.route('/logout').post(users.signout);

但问题是 res.redirect 使用的是 get 调用而不是 post 调用。 enter image description here

我知道我可以将它作为一个 get 调用来处理,但是有没有办法让 res.redirect 引发一个 post 调用?

【问题讨论】:

  • 大部分情况下是的。在您提到的答案中,他们使用了 app.post('/test', function(req, res) { res.send('/test page'); });在我的情况下,我没有应用参考,我只是提出一个 res.redirect(/logout) 你碰巧知道如何在我的情况下做同样的事情吗?

标签: node.js express routes express-router


【解决方案1】:

我不确定你是否可以从重定向中调用 POST 方法,但你可以做一些其他事情。

app.route('/logout/SpecificRoute').get(users.signout) {
    //Here you can write the code you wanted to execute in the POST method and if  
    //you want some data, you can use route params.
};
app.route('/logout').get(users.signout);

但如果您也使用带参数的路由,请务必在 app.route('/logout/:DataParams').get(users.signout) 之前致电 app.route('/logout/SpecificRoute').get(users.signout)before。

【讨论】:

    猜你喜欢
    • 2018-03-18
    • 1970-01-01
    • 2015-02-11
    • 1970-01-01
    • 2022-11-17
    • 1970-01-01
    • 1970-01-01
    • 2011-03-13
    • 1970-01-01
    相关资源
    最近更新 更多