search

Home  >  Q&A  >  body text

node.js - express 可以接受到post(抓包可以看到post的数据),但是body里面为空,为什么?

ringa_leeringa_lee2875 days ago553

reply all(1)I'll reply

  • 高洛峰

    高洛峰2017-04-17 16:27:37

    Express needs to use the body-parser middleware to parse the body

    var express = require('express')
    var bodyParser = require('body-parser')
    var app = express()
    var jsonParser = bodyParser.json()
    var urlencodedParser = bodyParser.urlencoded({ extended: false })
    app.post('/login', urlencodedParser, function (req, res) {
      if (!req.body) return res.sendStatus(400)
      res.send('welcome, ' + req.body.username)
    })
    

    soonfy

    reply
    0
  • Cancelreply