I have a server request that returns multiple cookies, like that:
This is how I'm storing these cookies to the cookieManager:
HttpURLConnection connection = ... ;
static java.net.CookieManager msCookieManager = new java.net.CookieManager();
msCookieManager.put(COOKIES_URI, connection.getHeaderFields());
This is how I'm adding these cookies to the next connection:
connection.setRequestProperty("Cookie",
msCookieManager.getCookieStore().get(COOKIES_URI).toString());
Is it the right way to get the cookies from the cookieManager?,
I'm quite sure there is a better one…
Best Answer
Ok, the right way to do it is just like that:
Get Cookies from response header and load them into cookieManager:
Get Cookies from cookieManager and load them into connection: