I would like to preserve a session while connecting to server using HttpGet and I need to understand how it handles cookies.
The server developer says that he handles all cookies stuff by himself. I use HttpGet request to access the server as follows: InputStream isResponse = null;
HttpGet httpget = new HttpGet(strUrl);
HttpResponse response = mClient.execute(httpget);
HttpEntity entity = response.getEntity();
isResponse = entity.getContent();
responseBody = convertStreamToString(isResponse);
return responseBody;
Should I do something more? Does he put the cookie on my device automatically and the HttpGet method knows to use it in order to keep the sessionID using the cookie?
How can I check if the cookie exist on my device, in order to know if the session is "alive"?
In case I use the following code to get the cookie:
CookieStore cookieStore = new BasicCookieStore(); // Create local HTTP context HttpContext localContext = new BasicHttpContext(); // Bind custom cookie store to the local context localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore); HttpGet httpget = new HttpGet(strUrl); HttpResponse response = mClient.execute(httpget,localContext);
does the HttpGet still handles the cookies the same as before?
- I see that DefaultHttpClient (mClient in the code above) has its own CookieStore. How can I save its cookies and load them next time I create it?