Android HttpClient persistent cookies Android HttpClient persistent cookies android android

Android HttpClient persistent cookies


You can do what @Emmanuel suggested or you can pass the BasicHttpContext between the HttpClients you are creating.

Example Use of context and cookies, complete code here

    HttpClient httpclient = new DefaultHttpClient();    // Create a local instance of cookie store    CookieStore cookieStore = new BasicCookieStore();    // Create local HTTP context    HttpContext localContext = new BasicHttpContext();    // Bind custom cookie store to the local context    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);    HttpGet httpget = new HttpGet("http://www.google.com/", localContext);


Don't create new HttpClients; this will clear the cookies. Reuse a single HttpClient.


Make your httpClient a singleton class.