有没有办法在使用 express.js 发送所有参数后进入?我知道如何分别知道 GET/POST,但是有没有办法同时获取所有内容?
到目前为止我还没有发现任何关于它的信息,它对调试特别有用。
当然 req.param(key)
可以工作,但我想要一个所有参数的列表,不必检索它们,只需查看它们即可。
编辑:添加路线信息:
consoleDev('Url: ' + req.method + ' ' + req.baseUrl + req._parsedUrl.href, 'debug');
consoleDev('Options: ' + JSON.stringify(options), 'debug');
consoleDev('Params: ' + Object.keys(req.params), 'debug');
consoleDev('Params: ' + (req.param('test')), 'debug');
控制台:
debug: Url: GET http://localhost:5000/?test=5000
debug: Options: {"controllerName":"home","methodName":"index"}
debug: Params:
debug: Params: 5000
最佳答案
我忘了几个月前我创建了这个主题并创建了另一个我得到问题答案的主题:
You're looking for req.body, which contains the parsed POST body. (assuming you have middleware that parses it)
See express.bodyParser()
关于javascript - 如何获取 express.js 中的所有参数(post/get/etc.),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21863415/