回答

13
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(); 
} 
+0

我希望這是可能得到HttpClient的的的的CookieStore沒有版本創建自己的HttpClientContext像3. – eztam

+2

@eztam:這是爲什麼? HttpClient總是需要一個執行上下文,所以如果沒有明確給出,會在場景後面創建。 – oleg

相關問題