gpt4 book ai didi

javascript - 从站点注销导致错误 : 400 - Bad Request

转载 作者:搜寻专家 更新时间:2023-10-30 22:49:07 24 4
gpt4 key购买 nike

我正在使用 vibed.org 框架。当我处理注销功能时,出现奇怪的错误。

这是我的 App.d 代码:

void main()
{
auto router = new URLRouter;
router.any("/checkAuthorization", &checkAuthorization);
router.any("/login", &login);
router.any("/logout", &logout);
// ..
}

...

    void logout(HTTPServerRequest req, HTTPServerResponse res)
{
logInfo("Logout section");
Json request = req.json;
Json answerJSON = Json.emptyObject;
if (req.session) // if user have active session
{
res.terminateSession();
answerJSON["status"] = "success";
answerJSON["isAuthorized"] = false;
res.writeJsonBody(answerJSON);

logInfo(answerJSON.toString);

logInfo("User %s logout", request["username"]); //
}
else
{
answerJSON["status"] = "fail"; // user do not have active session?
logInfo("User do not have active session");
}
}

和 Vue.JS 代码:

  function logout()
{
var loginData = new Object();
//data that we take from user input
loginData["username"] = this.username; // username more then enough
console.log("Logout username -> " + loginData["username"]);

this.$http.post('http://127.0.0.1:8080/logout', loginData["username"]).then(function (response) {
console.log("server response: ", response.data)
if(response.data["isAuthorized"] == false)
{
console.log("Logout from site success");
App.topMenuView = 'guestmenu' //Change current view!
userLoginNotification("Goodbye, " + loginData["username"], "User Logout"); // notificate user
}
});

}

但我在 Chrome 控制台出现错误:

Uncaught (in promise) Object {request: Object, data: "400 - Bad Request Bad Request 内部错误信息:std.json.JSONException@C:\vibe-d-0.7.27-alpha.1\source\vibe\data\json.d(1100): (0): Error: Expected 'true', got 'test'. -------------- 0x0044ABF0 in pure @安全 bool std.exception.enforceEx!(std.json.JSONException).enforceEx!(bool).enforceEx(bool, lazy immutable(char)[], immutable(char)[], uint) core.thread.Fiber.run ()", status: 400, statusText: "Bad Request", ok: false

我不明白哪里出了问题。它看起来像是服务器端的问题,因为 logInfo("Logout section"); 无法访问。

最佳答案

您发送的字符串为 loginData["username"] 而不是 {username:loginData["username"]} василий

关于javascript - 从站点注销导致错误 : 400 - Bad Request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34772662/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com