如何使用CookieManager特定域删除cookies吗? [英] How to remove cookies using CookieManager for a specific domain?

查看:764
本文介绍了如何使用CookieManager特定域删除cookies吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 CookieManager ,但我怎么删除域的饼干而已?

I know about the existince of CookieManager, but how do I remove cookies of a domain only?

有人可以帮助我做一些code片段?

Can someone help me with some code fragment?

推荐答案

呼叫 android.webkit.CookieManager 的getCookie 方法来生成一个RFC 2109 饼干您感兴趣的URL或域名的头。解析cookie头获得cookie名称的列表。对于每一个cookie的名称,生成一个RFC为具有到期日的过去和它传递到 CookieManager 设置Cookie 头code>的 setCookie方法方法。虽然API文档指定 setCookie方法忽略已过期的值,Android的当前实现真正冲在这种情况下,该cookie。为了防止未来的实现,这样做忽视,如文档中指定的过期值,检查饼干实际上取出,并执行一些备用的行为,如果他们没有 - CookieManager removeAllCookie 方法可用于此回退是有用的。

Call android.webkit.CookieManager's getCookie method to generate a RFC 2109 Cookie header for the URL or domain you are interested. Parse the cookie header to get a list of cookie names. For each cookie name, generate a RFC 2109 Set-Cookie header for that name that has an expiry date in the past and pass it into CookieManager's setCookie method. Although the API docs specify that setCookie ignores values that have expired, Android's current implementation actually flushes the cookie in this case. To guard against future implementations that do ignore expired values as specified in the documentation, check that the cookies were actually removed and perform some fallback behaviour if they haven't—CookieManager's removeAllCookie method may be useful for this fallback.

这篇关于如何使用CookieManager特定域删除cookies吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆