为什么req.params返回一个空数组? [英] Why does req.params return an empty array?

查看:187
本文介绍了为什么req.params返回一个空数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Node.js,我想查看已发布到我的脚本的所有参数。要获得我的功能,在我的 routes / index.js 我在做:

I'm using Node.js and I want to see all of the parameters that have been posted to my script. To get to my function, in my routes/index.js I'm doing:

app.post('/v1/order', order.create);

然后在我的函数中,我有:

Then in my function, I have:

exports.create = function(req, res, next) {
 console.log( req.params );

但它返回一个空数组。但是当我这样做:

But it's returning an empty array. But when I do:

exports.create = function(req, res, next) {
 console.log( req.param('account_id') );

我获取数据。所以我对这里发生了什么有点困惑。

I get data. So I'm a bit confused as to what's going on here.

推荐答案

req.params只包含路由参数,而不是查询字符串参数(来自GET),而不是主体参数(来自POST)。 param()函数检查所有三个,参见:

req.params only contain the route params, not query string params (from GET) and not body params (from POST). The param() function however checks all three, see:

http://expressjs.com/4x/api.html#req.params

这篇关于为什么req.params返回一个空数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆