CookieManager(CookieStore, CookiePolicy): This method is available in the java.net.CookieManager class of Java.
Syntax:
java.net.CookieManager.CookieManager(CookieStore store, CookiePolicy cookiePolicy)
This method takes two arguments. This method creates a new cookie manager with a specified cookie store and cookie policy.
Parameters: Two parameters are required for this method.
store: a CookieStore to be used by the cookie manager.if null, the cookie manager will use a default one, which is an in-memory CookieStore implementation.
cookiePolicy: a CookiePolicy instance to be used by the cookie manager as a policy callback. if null, ACCEPT_ORIGINAL_SERVER will be used.
Exceptions: NA
Approach
Java
package com.CookieManager;import java.net.CookieManager;import java.net.CookiePolicy;import java.net.CookieStore;import java.net.HttpCookie;import java.net.URI;import java.util.List;public class CookieManager2 {public static void main(String[] args) {CookieStore store = new CookieStore() {@Overridepublic boolean removeAll() {return false;}@Overridepublic boolean remove(URI uri, HttpCookie cookie) {return false;}@Overridepublic List<URI> getURIs() {return null;}@Overridepublic List<HttpCookie> getCookies() {return null;}@Overridepublic List<HttpCookie> get(URI uri) {return null;}@Overridepublic void add(URI uri, HttpCookie cookie) {}};CookiePolicy cookiePilocy = CookiePolicy.ACCEPT_ALL;CookieManager cookieManager = new CookieManager(store, cookiePilocy);System.out.println(cookieManager);}}
Output:
java.net.CookieManager@5d22bbb7
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