简体   繁体   English

如何在android中维护会话

[英]how to maintain session in android

I am new to android .In my application i need to maintain a session when first connection of web service(i need to implement java server web service urls when i call the first url i got response. after that second url call it gives the false response .thing is i need to call the url with in the same session as i called my first url) .I found different answers but i don't under stand those.what i am expecting is how to get the session id when my first call and how can i keep those in further activities. 我是android的新手。在我的应用程序中,第一次连接Web服务时我需要维护一个会话(当我调用第一个URL得到响应时,我需要实现Java服务器Web服务URL。在第二个URL调用之后,它给出了false response .thing是我需要在与我调用第一个url相同的会话中调用url)。我找到了不同的答案,但我不明白这些。我期望的是在我第一次访问时如何获取会话ID。电话,以及如何让他们继续开展活动。 please share sample code or related docs or relate answers.I hope you understand my intention . 请分享示例代码或相关文档或提供相关答案。希望您了解我的意图。

to get cookies or session from the server if using http client use this: 如果使用http客户端从服务器获取cookie或会话,请使用以下命令:

     List<Cookie> cookies = ((AbstractHttpClient) httpclient).getCookieStore().getCookies();

             if (cookies.isEmpty()) {
                Log.d("TAG","no cookies received");
             } else {
                for (int i = 0; i < cookies.size(); i++) {

                    if(cookies.get(i).getName().contentEquals("ASP.NET_SessionId")) {
                     asp = cookies.get(i).getValue();
                   }
                }
                Log.e("this is the cookiee", asp);
                }  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM