简体   繁体   中英

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. 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. This is a BUG , which will be hopefully solved in later versions. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM