How to work with Cookies in Android

Question:

I am making a request to the server that sets the PHPSESID in the cookie, I do it like this:

        response = httpClient.execute(httpPost, responseHandler);

        List<Cookie> cookiesReq = httpClient.getCookieStore().getCookies();
        if (!cookiesReq.isEmpty()) {
            Log.d(TAG + " : test cookie", url);
            String cookieStr = "";
            for (Cookie cookie : cookiesReq) {
                cookieStr += " " + cookie.getName() + "=" + cookie.getValue() + ";";
                Log.d(TAG, cookieStr);
            }
            if (!cookieStr.equals("")) {
                setCookiesPreference(cookieStr);
            }
        }

Those. I have to manually serve cookies for each request, is there a way to do it like in the browser, they set themselves without my supervision?

Answer:

Look towards CookieSyncManager

Scroll to Top