Android: Http response cookie store

2019-06-01 06:29发布

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.

1条回答
相关推荐>>
2楼-- · 2019-06-01 06:42

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();
查看更多
登录 后发表回答