开发者

Why is Android's DefaultHttpClient not restoring session as expected?

开发者 https://www.devze.com 2023-03-23 11:07 出处:网络
I am using Android\'s DefaultHttpClient to communicate with my server, I run into this weird problem.

I am using Android's DefaultHttpClient to communicate with my server, I run into this weird problem.

This is basically what I want to achieve: When one of my activity is closed(onPause is called), I store all my Cookies into SharedPreferences. And when another activity is activated, I restor开发者_JAVA技巧e the Cookies from SharedPreferences. By doing so, I can persist session between activities.

I achieved this by calling httpClient.getCookieStore().getCookies() and store all their information into SharedPrefenrences in my Activity's onPause mehod.

I restore it by retrieving cookies from SharedPrefenrences and call httpClient.getCookieStore().addCookie().

I have logged all the progress and saw no difference between the cookies when I stored them and the cookies when I retrieved then from SharedPrefrence.

The problem is it's not working, the server still thinks I am not logged in(I have logged in before I cleared all cookies and restore then from file).

0

精彩评论

暂无评论...
验证码 换一张
取 消