开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜