简体   繁体   English

请求主体在节点js中未定义

[英]Request body undefined in node js

I'm trying to get the username and password from a form: 我正在尝试从表单获取用户名和密码:

<!DOCTYPE html>

<form action="" method="post" enctype="application/x-www-form-urlencoded">  
  Username:<br>
  <input type="text" name="Username" value="Username">
  <br>
  Password:<br>
  <input type="text" name="Password" value="Password">
  <br><br>
  <input type="submit" value="Submit">
</form> 

This is then received by this: 然后通过以下方式接收到:

app.post('/login', function(req, res){
console.log(req.body.username);
console.log(req.body.password);
});

However no matter what enctype I put in, the username and password is always undefined. 但是,无论我输入什么enctype,用户名和密码始终是未定义的。 What is the error? 有什么错误?

PS Was using body-parser PS正在使用人体分析仪

Try 尝试

console.log(req.body.Username);
console.log(req.body.Password);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM