无法更新/删除针对Android的WebView特定的cookie(Impossible to up

2019-10-29 23:05发布

我想删除特定的Cookie为域,似乎是不可能的。
在网络视图onPageFinished我能看到的cookie和相关的URL。
我使用下面的代码删除cookie:


    CookieManager cm = CookieManager.getInstance();
    final String url = "https://server.com/foo/index.html?bar=1"; // this is the URL is see in the `onPageFinished`
    String cookiesString = cm.getCookie(url);  
    String [] cookies = cookiesString.split(";");
    for(String cookie:cookies) {
         String[] cookieParts = cookie.split("=");
         if(cookieParts.length <= 0) {
              continue;
         }
         if(cookieParts[0].trim().equals("xxxcookiename")) {
              cm.setCookie(url, cookieParts[0] + "=0;");
          }
          else {
              cm.setCookie(url, cookie);
          }
    }
    cm.flush();

What this does is append a `xxxcookiename=0;` in the cookies for the url. It does not replace/update the existing one with the value `=0`. I also have tried with `=;` and it does not replace it either. I also tried with `https://server.com/foo/index.html` and `https://server.com/foo`.

基本上,如果我叫cm.getCookie(url); 我冲右后我得到同样的cookie字符串如前面xxxcookiename=0; 附加与原xxxcookiename与旧值。 什么是这里的问题?

文章来源: Impossible to update/remove specific cookie for android webview