简体   繁体   English

Mern 全栈 req.body 为空

[英]Mern full stack req.body is empty

I am trying to connect my client with the backend.我正在尝试将我的客户端与后端连接。

This is my code:这是我的代码:

 //client const body = { email: value, }; axios.get("http://localhost:5000/checkEmail", body) //server.js const playerRoutes = require("./routes/playerRoutes"); server.use(bodyParser.json()); server.use((req, res, next) => { res.setHeader("Access-Control-Allow-Origin", "http://localhost:3000"); //allow the access, * it allow from anywhere like codepen res.setHeader("Access-Control-Allow-Methods", "GET, POST"); //to allow the METHODS res.setHeader( "Access-Control-Allow-Headers", "Content-Type, Authorization", "Content-Type, apllication/json" ); //to allow types of Headers next(); }); //playerRoutes.js const playerControllers = require("../controllers/playerControllers"); const router = express.Router(); router.post("/addPlayer", playerControllers.addPlayer); router.get("/checkEmail", playerControllers.checkEmail); //playerControllers exports.checkEmail = async (req, res, next) => { console.log(req.body); }

why in req.body i get empty object {}?为什么在 req.body 中我得到空的 object {}? I really can't solve the problem... can someone help me please?我真的无法解决问题...有人可以帮帮我吗?

checkEmail is a GET request, what else were you expecting, if you want to send a body change it to a POST request. checkEmail 是一个 GET 请求,如果您想发送正文,您还期待什么,请将其更改为 POST 请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM