Htmlunit cookie policy

How do you define a cookie policy in htmlunit to accept all cookies?

+3
source share
2 answers

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; //default
   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.

+3

.

  • cookieSpec.validate(cookie, cookieOrigin); org.apache.http.client.protocol.ResponseProcessCookies httpClient

  • htmlUnit com.gargoylesoftware.htmlunit.CookieManager

      public static final String HTMLUNIT_COOKIE_POLICY = CookiePolicy.BROWSER_COMPATIBILITY;
      ...
      final CookieSpec spec = registry_.getCookieSpec(HTMLUNIT_COOKIE_POLICY);
    

    CookieManager, )

     /**
      * HtmlUnit cookie policy is to be browser-compatible. Code which requires access to
      * HtmlUnit cookie policy should use this constant, rather than making assumptions and using
      * one of the HttpClient {@link CookiePolicy} constants directly.
      */
    

    , Cookie , CookiePolicy.BROWSER_COMPATIBILITY , .

+2

All Articles