在 node.js 中的 post 方法中接收多个参数
Reciving multiple parameters in post method in node.js
我有一个 Node.js 服务器正在处理 post 这样的方法:
app.post('/app/:id:second',function(req,res){
console.log('Post received');
res.end();
})
如何在 URL 中将 2 个或更多参数传递到我的服务器? url 应该是什么样子?我这样试过但失败了: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();
})
我有一个 Node.js 服务器正在处理 post 这样的方法:
app.post('/app/:id:second',function(req,res){
console.log('Post received');
res.end();
})
如何在 URL 中将 2 个或更多参数传递到我的服务器? url 应该是什么样子?我这样试过但失败了: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();
})