Java Utililty Methods Cookie

List of utility methods to do Cookie

Description

The list of methods to do Cookie are organized into topic(s).

Method

StringgetCookies(final URL url)
Returns the cookies returned by the server on accessing the URL.
final HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.setAllowUserInteraction(false);
urlConn.setDoInput(true);
urlConn.setDoOutput(false);
urlConn.setUseCaches(false);
urlConn.setRequestProperty(USER_AGENT_HEADER_NAME, USER_AGENT_PROPERTY_VALUE);
urlConn.connect();
final List<String> cookies = urlConn.getHeaderFields().get("Set-Cookie");
...
voidstoreCookies(HttpURLConnection connection)
store Cookies
Map<String, List<String>> headers = connection.getHeaderFields();
List<String> cookies = headers.get("Set-Cookie");
if (cookies != null) {
    for (String cookie : cookies) {
        cookieManager.getCookieStore().add(null, HttpCookie.parse(cookie).get(0));