原文链接:https://blog.csdn.net/cheny1p1ng/article/details/90780024
旧版本DefaultHttpClient 使用getCookieStore直接获取cookies信息,但是apache升级4.5后,DefaultHttpClient过期了,使用CloseableHttpClient做为替换获取cookies的代码如下:
//CloseableHttpClient替换DefaultHttpClient获取cookies CookieStore store = new BasicCookieStore(); CloseableHttpClient httpClient = HttpClients.custom().setDefaultCookieStore(store).build(); HttpResponse response = httpClient.execute(get); result = EntityUtils.toString(response.getEntity(),"utf-8"); System.out.printf(result); List<Cookie> CookieList = store.getCookies();
设置cookies信息
CloseableHttpClient httpClient = HttpClients.custom().setDefaultCookieStore(this.store).build();