Java – Conversion from httpclient 3 to httpclient 4 (cookie policy)

Conversion from httpclient 3 to httpclient 4 (cookie policy)… here is a solution to the problem.

Conversion from httpclient 3 to httpclient 4 (cookie policy)

Previously, I had the following code in httpclient3

// To prevent cookie warnings.
httpClient.getParams().setParameter("http.protocol.single-cookie-header", true);
httpClient.getParams().setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.BROWSER_COMPATIBILITY);

I

would like to know, what is the equivalent code in httpclient4 because I get the error on the second line.

// To prevent cookie warnings.
httpClient.getParams().setParameter("http.protocol.single-cookie-header", true);
// ??? compilation error in this line.
 org.apache.commons.httpclient cannot be resolved to a variable
httpClient.getParams().setCookiePolicy(org.apache.commons.httpclient.cookie.CookiePolicy.BROWSER_COMPATIBILITY);

Solution

This link can help you solve the problem.

http://www.wirelust.com/2009/03/29/howto-set-the-cookie-policy-with-apache-http-client-40/

So try this line:

httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);

Related Problems and Solutions