node.js express.js - req.body?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14008346/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:48:42  来源:igfitidea点击:

express.js - req.body?

node.jsexpress

提问by User_y

I'm new to js, I see this a lot in the code I'm reading

我是 js 的新手,我在我正在阅读的代码中看到了很多

_.pick(req.body, ' ' , ' ') 

What does req.body do? And when can I say req.body.something?

req.body 有什么作用?我什么时候可以说req.body.something?

回答by TomJ

req.bodyholds parameters that are sent up from the client as part of a POST request. See the API.

req.body保存作为 POST 请求的一部分从客户端发送的参数。请参阅API

// POST user[name]=tobi&user[email][email protected]
req.body.user.name
// => "tobi"

req.body.user.email
// => "[email protected]"

// POST { "name": "tobi" }
req.body.name
// => "tobi"

回答by Muo sigma classes

(req.body, ' ' , ' ') --> here req is the parameter of your function and using this parameter your can access the properties over then url.
so look this example
suppose this is form 
<form>
enter the name : <input type="text" name="name">
<button type ="submit"> submit </button> 
</form>

so if you want to access the name -- which is filled by the user end.
so for this you can 
do like this->   console.log(req.body.name);  -- this will print the name (property) in console.