最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

req.body.username是未定义

运维笔记admin57浏览0评论

req.body.username是未定义

req.body.username是未定义

快递JS,我用肢体解析器来获取用户名。当我尝试获取用户名,则返回undefined。谁能帮我?

app.use(session({
 cookieName: 'session',
 secret: "Shh_It's_a_secret",
 duration: 100000 * 100000
}));
app.use(bodyParser.urlencoded({ extended: true }));
app.get('/home', (req, res) => {
if(req.body.username){
 res.send('Invalid Username, Press The Back Button To Try Again');
} else if (!req.body.username) {
  app.use(express.static(__dirname + '/NerdFestProjectHomepage.html'));
  res.sendfile('NerdFestProjectHomepage.html');
  console.log(req.body.username);
}
})

当我试图让req.body.username,则返回undefined。

回答如下:

这是一个GET请求。在快递,不可能派“身体”使用GET请求。

更改GET到POST请求:

app.post('/home', cb );

并鉴于使用:

<form action="/home" method="POST"></form>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论