简体   繁体   中英

Reciving multiple parameters in post method in node.js

I have a Node.js server which is handling post methods like this:

app.post('/app/:id:second',function(req,res){
  console.log('Post received');
  res.end();
})

How can I pass 2 or more parameters to my server in a URL? How should the url look like? I tried it like this but it failed: http://localhost:8080/app/id=123&second=333
I'm a beginner in web apps.

Use bodyParser midleware, for example:

var bodyParser= require('body-parser');
app.use(bodyParser.urlencoded());

app.post('/app/:id',function(req,res){  //http://localhost:8080/app/123?second=333

  console.log(req.query); //{second: 333}
  console.log(req.params); // {id: 123}
  res.end();
})

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