Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving CookieStore in http client service

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?

like image 306
jlim Avatar asked Feb 09 '10 00:02

jlim


People also ask

Does HttpClient save cookies?

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.

What is closable HttpClient?

CloseableHttpClient is an abstract class which is the base implementation of HttpClient that also implements java. io. Closeable.


2 Answers

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)

like image 80
Bachi Avatar answered Oct 02 '22 21:10

Bachi


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).

like image 28
CommonsWare Avatar answered Oct 02 '22 21:10

CommonsWare