Some web sites, especially those driven by Microsoft products (in my experience), require that cookies be sent from the web browser back to the server using a single Cookie: http header. The default behavior of HtmlUnit, which uses
commons-httpclient, is to send multiple Cookie: headers, one for each cookie. See
Bug 1117500 for details.
In order to change the behavior of
commons-httpclient, the following code must be run before an http request is made to the web site.
DefaultHttpParams.getDefaultParams().setBooleanParameter(HttpMethodParams.SINGLE_COOKIE_HEADER, true);
Note that I have not tried this, but it is equivalent to the patch provided in
Bug 1117500.
This code may also help. It sets the browser compatibility mode of commons-httpclient to "compatibility" mode, the mode that is most compatible with current web browsers.
System.setProperty("apache.commons.httpclient.cookiespec", CookiePolicy.BROWSER_COMPATIBILITY);