Search code examples
javaspringapache-httpclient-4.xapache-commons-httpclientapache-httpcomponents

migration apache commons cookiePolicy to cookieSpec of httpClient4.3


I'm migrating httpClient 3.1 to 4.5.

The Orgignal code is:

httpGet.getParams().setCookiePolicy(CookiePolicy.RFC_2109);

And I want to change it to:

requestConfigBuilder.setCookieSpec(????)

I couldn't find how should it be changed...


Solution

  • You can use some of the cookie specs from org.apache.http.client.config.CookieSpecs:

      RequestConfig defaultRequestConfig = RequestConfig.custom()
            .setCookieSpec(CookieSpecs.DEFAULT)
    

    Check out the whole example: https://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientConfiguration.java