September 2019
Intermediate to advanced
816 pages
18h 47m
English
By default, JDK 11's HTTP Client supports cookies, but there are instances where built-in support is disabled. We can enable it as follows:
HttpClient client = HttpClient.newBuilder() .cookieHandler(new CookieManager()) .build();
So, the HTTP Client API allows us to set a cookie handler using the HttpClient.Builder.cookieHandler() method. This method gets an argument of the CookieManager type.
The following solution sets CookieManager that doesn't accept cookies:
HttpClient client = HttpClient.newBuilder() .cookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_NONE)) .build();
For accepting cookies, set CookiePolicy to ALL (accept all cookies) or ACCEPT_ORIGINAL_SERVER (accept cookies only from the original server). ...