有两种方式,一种是使用CookieStore实例 CookieStore cookieStore=new BasicCookieStore(); CloseableHttpClient httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build(); HttpGet get=new HttpGet("http://www.baidu.com/"); httpClient.execute(get); cookieStore.getCookies();//获取Cookie 另一种是使用HttpClientContext,使用内置CookieStore CloseableHttpClient httpClient = HttpClients.createDefault(); HttpGet get=new HttpGet("http://www.baidu.com/"); HttpClientContext context=HttpClientContext.create(); httpClient.execute(get,context); context.getCookieStore().getCookies();//获取Cookie
有两种方式,一种是使用CookieStore实例
另一种是使用HttpClientContext,使用内置CookieStore