nodejs接收get引數和post引數

不該相遇在秋天發表於2017-11-30

 

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

 

相關文章