Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the cookies from Apache HttpClient 4.x?

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.

like image 406
eztam Avatar asked Mar 05 '14 17:03

eztam


People also ask

Does HttpClient store cookies?

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.


1 Answers

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();
}
like image 135
ok2c Avatar answered Nov 12 '22 13:11

ok2c