我是 node js 的新手,正在開發一個簡單的網站。當向服務器發送未注冊的用戶名時,我得到的是“POST http://localhost:3001/auth/login 400(錯誤請求)”,而不是“用戶名/密碼不存在”。有人可以幫我解決這個問題嗎?謝謝。
我的中間件

我的帖子請求

我的路線
常量路由器 = 要求(“快遞”)。路由器();const {loginUser, registerUser} = require("../controllers/authController.js");
router.post('/register', registerUser); router.post('/login', loginUser);
module.exports = 路由器;
uj5u.com熱心網友回復:
我認為您收到此錯誤是因為您沒有將 傳遞userdata給login函式。我不確定,但請嘗試使用以下代碼:
const login = (loginUser, loginPassword) => {
axios.post('http://localhost:3001/auth/login', {
username: loginUser,
password: loginPassword
}).then(...)
}
uj5u.com熱心網友回復:
你有路線問題!在您的路線中,您有:
router.post('/login', loginUser);
在你的測驗中你有:
http://localhost:3000/auth/login
因此,您需要auth在您的路由定義中添加或auth在您的 axios 帖子中洗掉
uj5u.com熱心網友回復:
很多事情都可能出錯。我建議您只使用除錯器運行應用程式,然后逐行檢查有問題的地方。我看到您正在使用 Visual Studio Code。有很多關于如何使用除錯器運行應用程式的 Youtube 視頻。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/444073.html
上一篇:用貓鼬洗掉陣列中的子檔案
