Searched a lot.
I have an app. App logins on server and receive some cookies, then it can execute some POST requests with them (e.g. to get user profile). I want to
An implementation of java.net.CookieStore for providing persistent cookies.
Use this https://gist.github.com/manishk3008/2a2373c6c155a5df6326
Storing some data in CookieManager:
void populateCookieStore(URI uri)
throws IOException {
CookieManager cm = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cm);
Map<String,List<String>> header = new HashMap<>();
List<String> values = new ArrayList<>();
values.add("JSESSIONID=" + SESSION_ID + "; version=1; Path="
+ URI_PATH +"; HttpOnly");
values.add("CUSTOMER=WILE_E_COYOTE; version=1; Path=" + URI_PATH);
header.put("Set-Cookie", values);
cm.put(uri, header);
}
Now I'm using a PersistentCookieStorage class for those purposes. I create a singleton when the app is launched. It stores cookies in SharedPreferences.