Just recreate the entire CookieManager class: Here is the source of this class: http://jarvana.com/jarvana/view/net/sourceforge/htmlunit/htmlunit/2.8/htmlunit-2.8-sources.jar!/com/gargoylesoftware/htmlunit/CookieManager. java? format = ok
Now find this method public synchronized Set<Cookie> getCookies(final URL url)
there you will find the following:
public static final String HTMLUNIT_COOKIE_POLICY = CookiePolicy.BROWSER_COMPATIBILITY;
final CookieSpec spec = registry_.getCookieSpec(HTMLUNIT_COOKIE_POLICY);
for (final org.apache.http.cookie.Cookie cookie : all) {
if (spec.match(cookie, cookieOrigin)) {
matches.add(cookie);
}
}
Remove the specs matching operator if (spec.match(cookie, cookieOrigin)), you must accept all cookies regardless of policy. And / or you can process the ACCEPT_ALL_COOKIES flag and pass the specification if it is a policy specified in the configuration.