[英]Meteor Iron Router How to get POST data
I am trying to pass POST data to an Iron Router route from outside meteor but it doesn't work. 我试图将POST数据传递到外部流星的铁路由器路由,但它不起作用。 The request body is empty.
请求正文为空。
I have tried outputting the request body to check if the data were present, but it's just empty. 我已经尝试输出请求体来检查数据是否存在,但它只是空的。
Router.route('/api/gatewaysusers', function() {
body = this.request.body;
console.log(this.request)
// this.response.write(body);
this.response.end("Call served");
}, {where: 'server'})
Any idea ? 任何的想法 ? Thank you.
谢谢。
The request.body
is empty because iron-router
lacks middleware responsible for extracting url-encoded data. request.body
是空的,因为iron-router
缺少负责提取url编码数据的中间件。 This is a BUG , which will be hopefully solved in later versions. 这是一个BUG ,希望在以后的版本中解决。 For now you can just add:
现在你可以添加:
Router.onBeforeAction(Iron.Router.bodyParser.urlencoded({
extended: false
}));
somewhere on your server and it should work fine. 在您的服务器上的某个地方它应该工作正常。 Look here for more details.
在这里查看更多详情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.