-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CookiesStore.java 可能会有问题 #24
Comments
@xiaohangzhu 不太明白为啥会丢失所有cookie |
你试一下,如果某个请求返回了 两个 cookie ,一个需要持久化,一个不需要持久化, 在不需要持久化的时候 执行(prefsWriter.remove(url.host());) 4849出问题了 |
因为 url.host() 是一样的,所以会导致 获取的时候 就找不到第一个需要持久化的 cookie 了 |
建议去掉 prefsWriter.remove(url.host()); 或者 直接把持久化的判断去掉就好,都持久化 一般也没啥问题吧 |
@xiaohangzhu 这个也不是都持久化就没问题,而是为啥会出现一个请求有两个cookie,就算都持久化也保存不了两个cookie,除非保存的Key做区分 |
为啥不会有两个cookie来? 两个cookie key-value 不一样啊,但是 url.host() 是一样的,本来这个持久化就是分开保存的,只是以url.host() 为索引 ,再去取对应 url的 cookie 值 持久化 |
if (cookie.persistent()) {//需要持久化
//将cookies持久化到本地
prefsWriter.putString(url.host(), TextUtils.join(",", cookies.get(url.host()).keySet()));
prefsWriter.putString(name, encodeCookie(new OkHttpCookies(cookie)));
prefsWriter.apply();
} else {//不需要持久化
prefsWriter.remove(url.host());
prefsWriter.remove(name);
prefsWriter.apply();
}
这段代码,会导致所需的cookie 丢失
The text was updated successfully, but these errors were encountered: