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

Hi

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

BR
Martin
mardah
Freshman
Freshman
 
Posts: 3
Joined: Fri Nov 13, 2009 1:04 pm

Top

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.

UPD:

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.031 seconds, using GeSHi 1.0.8.4


And add to your HttpClient:

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


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

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: Exabot [Bot] and 4 guests