我瘋狂使用sparkjava簡單的java web應用程序。它的字段是GET和POST請求。我做了我自己的簡單的驗證腳本,用於認證使用祕密密碼的用戶並存儲在會話中的用戶名:從命令行使用捲曲時會話死亡
/*
Make sure authenticated
*/
before((req, res) -> {
boolean authenticated = false;
if (req.session().attribute("user") != "casumo_user") {
try{
if (req.queryParams("secret").equals(System.getenv().get("SECRET"))){
authenticated = true;
req.session().attribute("user","casumo_user");
}
}catch (Exception e){
halt(401, "{\"error\":\"Please Authenticate.\"}");
}
}else{
authenticated = true;
}
if (!authenticated) {
halt(401, "{\"error\":\"Please Authenticate.\"}");
}
});
我用的是Postman Add-on for Chrome,這是工作的罰款。我會驗證一次,並且服務器會保留我的會話以備後續請求使用。
問題是我想用curl來做出相同的請求,但會話並沒有從一個請求保持活動。
例如,首先我用這個命令:
curl -s -L --data "secret=secret_password" url/auth | jsonpp
{ 「味精」: 「通過身份驗證的現在,您可以提出請求」 }
但隨後作出sebsequent GET請求證明會話不保留/
curl -s -L url/films | jsonpp
{ 「錯誤」: 「請驗證。」 }
使用郵遞員應用程序將允許我進行GET和POST請求一段時間後認證一段時間。是否有可能使用像我這樣的命令行使用curl來做到這一點?或者,我的身份驗證系統不夠健壯,無法從命令行使用curl?
謝謝!
我一直在爲此挖掘數小時,工作! – Aproram