express-post 请求
1.导入body-parser
yarn add body-parser
2、配置
const bodyParser=require('body-parser')
const app = express()
app.use(bodyParser.json())//可以处理json
// app.use(bodyParser.urlencoded({ extended: false })) //只能处理urlencoded
app.post('/',function(req,res){
console.dir(req.body)
res.send('ok')
})
灵活处理urlencoded和jison
//灵活处理 var jsonParser = bodyParser.json() var urlencodedParser = bodyParser.urlencoded({ extended: false }) app.post('/post/a',jsonParser,function(){ console.log(req.body) send.send('hell0') }) app.post('/post/b',urlencodedParser,function(){ console.log(req.body) send.send('hello') })
浙公网安备 33010602011771号