CookieManager getCookieStore() in Java

getCookieStore(): This method is available in the java.net.CookieManager class of Java.

Syntax:

CookieStore java.net.CookieManager.getCookieStore()

To retrieve current cookie store.

Parameters: NA

Returns: the cookie store currently used by cookie manager.

Exceptions: NA

Approach

Java

package com.CookieManager;

import java.net.CookieManager;

public class CookieManagergetCookieStore {
    public static void main(String[] args) {

        CookieManager cookieManager = new CookieManager();

        System.out.println(cookieManager.getCookieStore());
    }
}

Output:

java.net.InMemoryCookieStore@2d363fb3


Some other methods of CookieManager

CookieManager()Create a new cookie manager.

CookieManager(CookieStore, CookiePolicy)This method creates a new cookie manager with a specified cookie store and cookie policy.

get(URI, Map)This method gets all the applicable cookies from a cookie cache for the specified uri in the request header.

getCookieStore()To retrieve current cookie store.

put(URI, Map)This method sets all the applicable cookies, examples are response header fields that are named Set-Cookie2, present in the response headers into a cookie cache.

setCookiePolicy(CookiePolicy)To set the cookie policy of this cookie manager.

No comments:

Post a Comment