Retain cookies for httpclient?

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Retain cookies for httpclient?

Postby mardah » Mon Nov 30, 2009 9:51 am


I'm using httpclient to get data from a server which sets a cookie. The cookie is stored in a CookieStore specified by me in the http context. If I have a global CookieStore I can retain the cookies as long as my application/process is running.

How do I retain cookies for a longer period of time? I can't find any methods that allows me to save the CookieStore to the filesystem. I have searched a lot but didn't find a solution.

Please help

Posts: 3
Joined: Fri Nov 13, 2009 1:04 pm


Postby Romeo Ordos » Tue Dec 08, 2009 10:13 am

Joining to topic.

You can save cookies to SharedPrefernces as strings. And restore them after app restart or whenever you want.


To add your cookies to httpclient you need to create new Cookie:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. BasicClientCookie c = new BasicClientCookie("name", "value");
Parsed in 0.014 seconds, using GeSHi

And add to your HttpClient:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. ((AbstractHttpClient)client).getCookieStore().addCookie(c);
Parsed in 0.010 seconds, using GeSHi

That's all!
Romeo Ordos
Junior Developer
Junior Developer
Posts: 11
Joined: Thu Aug 06, 2009 6:30 pm
Location: Donetsk, Ukraine


Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 2 guests