1

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.

4

1 回答 1

8

如果您使用的是扩展AbstractHttpClient的客户端,例如DefaultHttpClient,您可以在执行请求后执行以下操作来获取 cookie。

List<Cookie> cookiejar = client.getCookieStore().getCookies();
于 2013-06-04T21:26:45.007 回答