axios({ method: 'post', url: 'http://localhost:3000/verify', headers: { 'Content-Type': 'application/x-www-form-urlencoded', 'Accept': 'text/json' }, data: { buyParam: JSON.stringify([{ "goodsId": 5977, "amount": 1 }, { "goodsId": 5978, "amount": 1 }]) }}).then((res) => { console.log(res)})router.post('/verify', cors(), function(req, res, next) { console.log(req) console.log(req.body) console.log(req.body.buyParam) res.json(req.body.buyParam); // res.json({ // code: 0, // msg: '' // });});req.body.buyParam // undefined
1 回答
交互式爱情
TA贡献1712条经验 获得超3个赞
npm install body-parser
var express = require('express')
var bodyParser = require('body-parser')
var app = express()
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
app.use(function (req, res) {
res.end(JSON.stringify(req.body, null, 2))
})
添加回答
举报
0/150
提交
取消