How do I get the cookies from an existing object of type HttpClient? I'm using HttpClient version 4.3.3 which has no method httpClient.getCookieStore() anymore.
HttpClient supports automatic management of cookies, including allowing the server to set cookies and automatically return them to the server when required. It is also possible to manually set cookies to be sent to the server.
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpClientContext context = HttpClientContext.create();
CloseableHttpResponse response = httpclient.execute(new HttpGet("/"), context);
try {
CookieStore cookieStore = context.getCookieStore();
List<Cookie> cookies = cookieStore.getCookies();
} finally {
response.close();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With