how to remove specific cookie value?

蹲街弑〆低调 提交于 2019-12-20 10:01:01

问题


In my app there are facebook and twitter login using browser and after login it stores cookies automatically. i have to logout facebook that will be happen to remove facebook cookies value but i don't know how to remove particular cookies.

if i remove all cookies using:

CookieManager cm = CookieManager.getInstance(this);
cm.removeAllCookies();

but it removes all cookies value means it will logout both facebook and twitter both.

my question is -- how to remove particular cookie value.

thanks..


回答1:


You should use CookieManager.setCookie() and set the cookie to the empty string. Something like this should work:

String cookieString = "cookieName=''";
cookieManager.setCookie(cookieDomain, cookieString);

In addition to setting the cookie value to empty, you can also expire the cookie by setting the 'expire' value in the cookie string to a time in the past. For example:

String cookieString = "cookieName=;expires=Mon, 17 Oct 2011 10:47:11 UTC;";


来源:https://stackoverflow.com/questions/7802364/how-to-remove-specific-cookie-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!