Handling Session Cookie in Android Volley

我与影子孤独终老i 提交于 2019-12-20 10:46:28

问题


For those unfamilar with Volley its a networking library and,it will switch its http request client from HttpUrlConnection or HttpClient depending on android version, so one thing I need to know is how to add cookie support to each of these client types. How do I opt in to session management for both types of clients?

I have seen this solution: Using cookies with Android volley library

which is a good step in the right direction. Has anyone found a way to push this logic a level down into the library without using preferences? or references from Volley into the application. I don't mind rewriting the Volley helper class to apply some support for this but not sure if both types of http clients support cookies and what exactly I would need to do to turn on cookie support?

also is there a way to use Volley with CookieManager perhaps?


回答1:


Take a look at my answer on the other question you linked. By specifying the HttpClient for Volley to use, it will only ever use that one for connections. Thus obviating the need to set cookies on both.




回答2:


For handling session cookies, I use CookieManager and a own implementation of CookieStore. Here I show a implementation of this, storing the cookie in SharedPreferences



来源:https://stackoverflow.com/questions/18413846/handling-session-cookie-in-android-volley

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!