From: Chris P. <ch...@fo...> - 2004-01-19 09:08:31
|
G'day, htm...@li... wrote: >>>web_client.addRequestHeader("Cookie", COOKIE); >>>page = (HtmlPage) web_client.getPage("http://localhost/cgi-bin/printenv"); >> >>I would have expected that to work but perhaps common-httpclient is >>stripping that header out. You are correct, see HttpMethodBase.addCookieRequestHeader() <http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java?view=markup> "Cookie" headers are removed in preference for those set in the HttpState. As a result, I use the following workaround: // Visit the domain for which the cookie is to be set. web_client.getPage(url); // Get the state for the domain - N.B. getWebConnection() is volatile. HttpState state = web_client.getWebConnection().getStateForUrl(url); // Set cookies. state.addCookies(new Cookie[]{ ... }); Additionally, for our server configuration I need to do the following *first* (need commons-httpclient nightly build - not yet in commons-httpclient-2.0-rc3): // Cookies in one header. HttpMethodParams.getDefaultParams().setParameter( HttpMethodParams.SINGLE_COOKIE_HEADER, new Boolean(true)); YMMV, Chris. |