-
Notifications
You must be signed in to change notification settings - Fork 247
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
I am using okhttp3 followed by retrofit2 and the next time cookies are lost #14
Comments
I am having same problem. When I restart the application then cookies are lost. |
Have you checked that your cookies have an expire or max-age attribute? If they do not they are session cookies and should be "lost" each time you reset your app. |
Yes it was a session thing you mentioned and I made it to work using a remember parameter in the API. I am facing another issue. There is a comment endpoint which posts new comment on server, when I hit the endpoint on first attempt, it doesn't works but on the second attempt it works and responds accordingly. On the first attempt it is not able to use the cookies thing as it asks me to login first. |
Yeah, seems the library is useless as cookies are being cleared after application restart. |
@Leonid-Kiev if you have any problem you are welcome to create a test reproducing the issue. Even you can create a PR fixing the issue. Although my first recommendation would be to check if your cookies attributes are the correct ones according to the RFC 6265 |
Thanks. |
In class |
@wangdandong with your solution the library will persist all cookies, if you do not have access to the server to configure the cookies properly can be good workaround but the real good solution is to configure correctly the cookies with an expire date so the cookies can be persisted. A more elegant workaround when you do not have access to the server but you need to persist the cookies is to create a OkHttp Interceptor that takes the incoming cookies and add to them a expire date. |
@wangdandong 非常感谢,之前的问题就是框架没保存sessionID 。很奇怪为什么这个框架默认要过滤掉sessionID。 |
I am using okhttp3 followed by retrofit2 and the next time cookies are lost below is my code and
public static ClearableCookieJar cookieManager = new PersistentCookieJar(new SetCookieCache(), new SharedPrefsCookiePersistor(context)); public static ClearableCookieJar getCookieManager() { return cookieManager; }
`OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(NETWORK_TIMEOUT, TimeUnit.SECONDS);
builder.readTimeout(READ_TIMEOUT, TimeUnit.MINUTES);
builder.cookieJar(TrestApplication.getCookieManager());
The text was updated successfully, but these errors were encountered: