using retrofit with Cookie persistence

后端 未结 1 1482
太阳男子
太阳男子 2020-12-29 13:24

I guys, I\'m using retrofit and I wonder how to transparently handle the session cookie. For that I extend the given ApacheClient and use a CookieStore in the custom call to

相关标签:
1条回答
  • 2020-12-29 14:06

    Starting from API 9 you have java.net.CookieManager and can set system-wide cookie handler like this:

    CookieManager cookieManager = new CookieManager();
    cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cookieManager);
    

    Yes, Apache Http client uses its own cookie-handling mechanism. But it should not be the problem because starting from API 9 HttpURLConnection is recommended HTTP client. If you use Retrofit from Square you may also like their OkHttp lib - custom URLConnection implementation with lots of useful capabilities.

    0 讨论(0)
提交回复
热议问题