Question

I cant find any resource to understand how cookies are set by the Http response in Android. I am hitting a URL and reading the response like so:

            HttpGet httpGet = new HttpGet(url);
        HttpResponse response = client.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            String entityStr = EntityUtils.toString(entity);
                }

I am told that Http response will set a cookie that will be read by another service later. Is there anything that I need to do to ensure the cookie is set? How can I verify that the cookie is being set. Thanks.

Was it helpful?

Solution

If you are using a client which extends AbstractHttpClient, such as DefaultHttpClient you can do the following to get the cookies after executing the request.

List<Cookie> cookiejar = client.getCookieStore().getCookies();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top