【问题标题】:What unique functionality does app.post( .. ) provide, in Express.js在 Express.js 中 app.post( .. ) 提供了哪些独特的功能
【发布时间】:2013-08-18 08:45:15
【问题描述】:

app.post 没有记录在 expressjs.com 中。据我了解,服务器侦听 url 请求 / 等,然后调用中间件和回调。但所有这些在app.get 中都是一样的。

它有什么独特的价值去表达?

PS。还有其他问题,例如 Express Framework app.post and app.getapp.use and app.get (or app.post) node.js express,但阅读相同问题的答案并不能提供问题的答案。

编辑:

以下代码提供对来自浏览器的/login 请求的app.getapp.post 调用。 app.getapp.post 都被调用了吗? (大概是按出场顺序吧。)

app.get('/login', function(req, res){
var username = req.user ? req.user.username : ''; res.render('login', { title: 'authenticate', username: username,
});
message: req.flash('error') });
app.post('/login',
passport.authenticate('local', { failureRedirect: '/login', failureFlash: true }), function(req, res) {
res.redirect('/admin'); });

enter code here

【问题讨论】:

    标签: node.js express


    【解决方案1】:

    我不会说它是not documented,但基本上它与app.get()HTTP GET 的作用相同,但只匹配HTTP POST 请求。

    如果您不知道POSTGET 之间的区别是什么,您可以看看here

    至于您的示例代码,您的 get 或您的 post 处理程序会被调用,具体取决于浏览器是执行 post 还是 get 请求。永远不会为同一个请求调用两者。

    【讨论】:

    • 您提供的“此处”链接是指 html 2.0 标准。它们仍然适用吗? (在 html 5 中,世界)这似乎是一个非常有用的链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-29
    • 1970-01-01
    • 2019-07-13
    • 1970-01-01
    • 1970-01-01
    • 2014-02-21
    • 2012-03-25
    相关资源
    最近更新 更多