6
如何從HttpClient類型的現有對象獲取Cookie? 我使用HttpClient版本4.3.3,它沒有方法httpClient.getCookieStore()了。如何從Apache HttpClient 4.x獲取cookie?
如何從HttpClient類型的現有對象獲取Cookie? 我使用HttpClient版本4.3.3,它沒有方法httpClient.getCookieStore()了。如何從Apache HttpClient 4.x獲取cookie?
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();
}
我希望這是可能得到HttpClient的的的的CookieStore沒有版本創建自己的HttpClientContext像3. – eztam
@eztam:這是爲什麼? HttpClient總是需要一個執行上下文,所以如果沒有明確給出,會在場景後面創建。 – oleg