/** | |
* 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()); |
This comment has been minimized.
This comment has been minimized.
Look elsewhere on how to use as a singleton. I use Dagger to inject my OkHttpClient, for example. |
This comment has been minimized.
This comment has been minimized.
with lib 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0' it as simple as just add |
This comment has been minimized.
This comment has been minimized.
I had some problems with this implementation, because you send back the cookies exactly as you get them, but it can append that there are more cookies with the same name, in my case the server sent me two phpsessid and it ended up with Unauthorized user. We need a cookie manager so marcinOz implementation is more accurate. And I would add that this is also for older version of okhttp-urlconnection. |
This comment has been minimized.
This comment has been minimized.
This works create. Thanks buddy. |
This comment has been minimized.
This comment has been minimized.
Thanks |
This comment has been minimized.
This comment has been minimized.
https://gist.github.com/nikhiljha/52d45ca69a8415c6990d2a63f61184ff I made a one size fits all, drag and drop approach based off of your gist. This will "just work" and shouldn't require any work on your part (I hope). Enjoy! |
This comment has been minimized.
This comment has been minimized.
Thank you nikhiliha & tsuharesu Thanks! |
This comment has been minimized.
This comment has been minimized.
cool |
This comment has been minimized.
This comment has been minimized.
is that means the app runs without worrying statefull web app sessions? |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
cool thanks |
This comment has been minimized.
This comment has been minimized.
Hey bro session id getting refreshed again and again what might be the reason. ? |
This comment has been minimized.
This comment has been minimized.
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. |
This comment has been minimized.
This comment has been minimized.
Kotlin version with helper methods to create OkHttp client and Retrofit instance: https://gist.github.com/nikhiljha/52d45ca69a8415c6990d2a63f61184ff#gistcomment-2310417 |
This comment has been minimized.
This comment has been minimized.
Thank |
This comment has been minimized.
This comment has been minimized.
@arvi can you please let me know how can you do that. persists server request cookie even if app is destroyed!. This one |
This comment has been minimized.
This comment has been minimized.
Please the cookies are of which type e.g strings e.t.c cos i need that to create a custom response for retrofit |
This comment has been minimized.
This comment has been minimized.
How to get url in AddCookiesInterceptor |
This comment has been minimized.
This comment has been minimized.
Thanks |
This comment has been minimized.
This comment has been minimized.
I used above steps to store the cookie then add on request. |
This comment has been minimized.
This comment has been minimized.
It really works. Thanks |
This comment has been minimized.
Hey please can u provide an overall to how to implement this in singleton way.