简体   繁体   中英

Parsing POST request from Twilio in NodeJS/Express

I'm a Node newbie. I'm trying to figure out a way to get the data from a POST request. My code currently looks like this:

var bodyParser=require("body-parser");
app.use(bodyParser.json());

app.post('/hello', function(req,res){
    console.log(req.body);
});

This results in [object Object] being written instead of what I wanted. I added the bodyParser part on someone's recommendation but I don't know how to get the JSON data that Twilio sends in the body. Any help is appreciated!

app.post('/hello', function(req,res){
    console.log(JSON.stringify(req.body));
})

You are basically logging an object directly which usually means Object.toString() gets called directly instead of logging the body contents as JSON

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