Javascript 无法从expressJS中的post方法接收有效负载

Javascript 无法从expressJS中的post方法接收有效负载,javascript,express,Javascript,Express,您好,我正在使用express for server一切正常,但我没有从post方法接收数据。我也在使用主体解析器 const express = require("express") const app = express() var bodyParser = require('body-parser') app.use(bodyParser.urlencoded({ extended: false })) app.use(bodyParser.json()) app.post("/sig

您好,我正在使用express for server一切正常,但我没有从post方法接收数据。我也在使用主体解析器

const express = require("express")
const app = express()
var bodyParser = require('body-parser')  
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.post("/signup", (req,res)=>{
    var data = req.body
    res.send(req.body)
})

这是一个100%的工作代码。如果它不起作用,那么告诉我你是如何提出POST请求的

const express = require("express")
const app = express()
const bodyParser = require('body-parser')

app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
app.post("/signup", (req, res) => {
  var data = req.body
  console.log(data)
  res.send(req.body)
})

app.listen(3000)
前端:

axios.post('http://localhost:3000/signup', {
  firstName: 'Fred',
  lastName: 'Flintstone'
})
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

你能登录你在req.body上得到的东西吗?另外,您在发布时是否在身体中发送数据是的,我在身体中提供数据,它显示一个空对象有效负载是什么格式的?仍然不工作:(.Iam使用postman get,put all方法工作正常这里是我的数据{“username”:“ammar”,“pass”:“123”}像这样尝试:postman:-POST-body=raw={test:“123”}不,不,我试图说除了postAdd头以外的所有其他方法都可以正常工作:Key:Content-Type-Value:application/json{test:“123”}它可以工作!!但是我收到的数据是这样的{{\ntest:\“123”,\n}”:“}”