try {
CookieManager manager = new CookieManager();
CookieHandler.setDefault(manager);
CookieStore cookieJar = manager.getCookieStore();
HttpCookie cookie = new HttpCookie("user", username);
URL url = new URL("http://host.example.com");
cookieJar.add(url.toURI(), cookie);
System.out.println("Added cookie using cookie handler");
} catch(Exception e) {
System.out.println("Unable to set cookie using CookieHandler");
e.printStackTrace();
}
我将如何添加 cookie 过期的时间,因为现在它更像是一个会话 cookie。每次应用程序被销毁/关闭时它都会过期