i have login to a site through WebView. then i have get cookie which is set by the webview at login time. then i have tried to set the cookie later. please see my code:
CookieSyncManager.createInstance(context);
CookieManager cookieManager = CookieManager.getInstance();
Log.e("checkPost 1", cookie);
cookieManager.setCookie("https://************", cookie);
Log.e("checkPost 2", cookieManager.getCookie("https://*************"));
CookieSyncManager.getInstance().sync();
Log.e("checkPost 3", cookieManager.getCookie("https://*************"));
in checkPost 1
printed cookie shows that it is fine. but in checkPost 2
and after sync()
it by CookieSyncManager.getInstance().sync();
statement, the checkPost 3
shows that most of the cookie is vanished. what is the problem ? i need to set the cookie. but i could not find a way spending about 2 days.
Edit:
in android documentation it says that:
public void setCookie (String url, String value)
Sets a cookie for the given URL. Any existing cookie with the same host, path and name will be replaced with the new cookie. The cookie being set must not have expired and must not be a session cookie, otherwise it will be ignored.
is there any way to force CookieManager
set session cookie via setCookie()
?
i think the problem is, may be i am trying to set session cookie