How to remove cookies using CookieManager for a specific domain?

前端 未结 4 1050
半阙折子戏
半阙折子戏 2020-12-14 13:08

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

Can someone help me with some code fragment?

4条回答
  •  囚心锁ツ
    2020-12-14 13:35

    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.

提交回复
热议问题