dongpou1935 2012-11-08 05:57
浏览 28
已采纳

使用Web服务器时维护会话

I am using the simplest way to maintain sessions, which is:

Just create 1 HttpClient and use it for every server call, which will automatically handle cookies etc..,

But the problem here is, when i close the application, the HttpClient object is being destroyed, as expected and hence i cannot login.

So i fixed it, this way:

Store user-email and password in shared preferences, every time the application is launched make a call to the login function(this creates a new session) and use the same HttpClient.

The problem here is, every session in the web server has an expiry duration of 3 years. Where as i am creating a session (Since i am calling login every time user launches the app), every time user launches the app. Which causes session duplication or say unnecessary sessions being created on the server side.

Am i doing it the right way? How can i solve this?

Thank You

  • 写回答

2条回答 默认 最新

  • doujingao6210 2012-11-08 06:33
    关注

    Just implement your own CookieStore. It's pretty easy: Extend BasicCookieStore, instantiate it and pass it in the HttpContext. You can store it against a sqlite database, or even just dump it to an xml file (but sqlite is lighter). I have it working here, but I don't time to sanitize the code right now.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计