JMH*_*bog 45
我找到了答案.其中一个插件需要激活, restify.bodyParser.然后可以在req.params(默认)或req.body(mapParams: false)中找到数据,具体取决于设置(具体来看BodyParser部分).
例:
server.use(restify.bodyParser({ mapParams: false })); // mapped in req.body
Run Code Online (Sandbox Code Playgroud)
要么:
server.use(restify.bodyParser()); // mapped in req.params
Run Code Online (Sandbox Code Playgroud)
对于restify 5.0.0+,使用:
server.use(restify.plugins.bodyParser());
Run Code Online (Sandbox Code Playgroud)
https://github.com/restify/node-restify/issues/1394#issuecomment-312728341
对于旧版本,请使用:
server.use(restify.bodyParser());
Run Code Online (Sandbox Code Playgroud)
在告诉restify使用bodyParser中间件后,请求主体将在请求对象的body属性上可用:
server.post('/article', (req, res, next) => {
console.log(req.body)
next()
})
Run Code Online (Sandbox Code Playgroud)
很简单:
server.use(restify.bodyParser({ mapParams: false }));
Run Code Online (Sandbox Code Playgroud)
你需要在restify中激活bodyParser
| 归档时间: |
|
| 查看次数: |
13840 次 |
| 最近记录: |