nodejs接收get参数和post参数

 

get请求用query

//http://localhost:3000?a=3&b=4&c=5
router.get('/', function (req, res, next) {
   console.log(req.method);//get
    console.log(req.query);//{ a: '3', b: '4', c: '5' }
    console.log(req.query.a); //3
});

 

post请求用body

router.post('/', function (req, res, next) {
   console.log(req.method);//post
    console.log(req.body);//{ a: '3', b: '4', c: '5' }
    console.log(req.body.a); //3
});

 

posted @ 2017-11-30 15:21  不该相遇在秋天  阅读(7150)  评论(1编辑  收藏  举报