繁体   English   中英

在node.js中的post方法中接收多个参数

[英]Reciving multiple parameters in post method in node.js

我有一个Node.js服务器,正在处理这样的发布方法:

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

如何通过URL向服务器传递2个或更多参数? 网址应如何显示? 我这样尝试过,但失败了: http://localhost:8080/app/id=123&second=333
我是网络应用的初学者。

使用bodyParser中间件软件,例如:

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();
})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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