I am using HttpClient 4.1.2
HttpGet httpget = new HttpGet(uri);
HttpResponse response = httpClient.execute(httpget);
So, how can I get the
Not sure why the accepted answer describes a method getCookieStore()
that does not exist. That is incorrect.
You must create a cookie store beforehand, then build the client using that cookie store. Then you can later refer to this cookie store to get a list of cookies.
/* init client */
HttpClient http = null;
CookieStore httpCookieStore = new BasicCookieStore();
HttpClientBuilder builder = HttpClientBuilder.create().setDefaultCookieStore(httpCookieStore);
http = builder.build();
/* do stuff */
HttpGet httpRequest = new HttpGet("http://stackoverflow.com/");
HttpResponse httpResponse = null;
try {httpResponse = http.execute(httpRequest);} catch (Throwable error) {throw new RuntimeException(error);}
/* check cookies */
httpCookieStore.getCookies();