I have a Service for my Android app that performs HTTP calls. The Service stores cookies in a CookieStore. I am trying to find a way to persist the CookieStore but I haven't been successful. I don't want the user to log in every time to receive a new CookieStore.
I tried to use SharedPreferences to store the CookieStore as a string, but I can't re-construct the CookieStore with a String.
Has anyone else had success in persisting a CookieStore?
HttpClient supports automatic management of cookies, including allowing the server to set cookies and automatically return them to the server when required. It is also possible to manually set cookies to be sent to the server.
CloseableHttpClient is an abstract class which is the base implementation of HttpClient that also implements java. io. Closeable.
There is a nice library for handling various aspects of http requests, among them persisting cookies in the shared preferences: http://loopj.com/android-async-http/
(you can use the full lib or just the the two classes needed for cookie persistence)
You can create your own CookieStore
implementation. Bear in mind that HttpClient isn't an Android-specific technology, so you will find some documentation over at the Apache site (see section 3.7).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With