簡體   English   中英

Mern 全棧 req.body 為空

[英]Mern full stack req.body is empty

我正在嘗試將我的客戶端與后端連接。

這是我的代碼:

 //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); }

為什么在 req.body 中我得到空的 object {}? 我真的無法解決問題...有人可以幫幫我嗎?

checkEmail 是一個 GET 請求,如果您想發送正文,您還期待什么,請將其更改為 POST 請求。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM