-
-
Save tsuharesu/cbfd8f02d46498b01f1b to your computer and use it in GitHub Desktop.
/** | |
* Somewhere you create a new OkHttpClient and use it on all your requests. | |
*/ | |
OkHttpClient okHttpClient = new OkHttpClient(); | |
okHttpClient.interceptors().add(new AddCookiesInterceptor()); | |
okHttpClient.interceptors().add(new ReceivedCookiesInterceptor()); |
cool thanks
Hey bro session id getting refreshed again and again what might be the reason. ?
Thank you so muuuuuch! For some reason, answer from SO https://stackoverflow.com/a/36865953/2098493 didn't work for me and also https://github.com/franmontiel/PersistentCookieJar.
Your solution persists server request cookie even if app is destroyed! :) I'm so happy. Finally found the right one.
Kotlin version with helper methods to create OkHttp client and Retrofit instance: https://gist.github.com/nikhiljha/52d45ca69a8415c6990d2a63f61184ff#gistcomment-2310417
Thank
@arvi can you please let me know how can you do that. persists server request cookie even if app is destroyed!. This one
Please the cookies are of which type e.g strings e.t.c cos i need that to create a custom response for retrofit
How to get url in AddCookiesInterceptor
Thanks
I used above steps to store the cookie then add on request.
Worked on actively on login and continue use.
But once close and open the app not worked.
(Once restart the comes CSRF token invalid issue.)
It really works. Thanks
for (String cookie : preferences) { builder.addHeader("Cookie", cookie); Log.v("OkHttp", "Adding Header: " + cookie); // This is done so I know which headers are being added; this interceptor is used after the normal logging of OkHttp }
so a request has multi Cookie ?