문제

How do I get the cookies from an existing object of type HttpClient? I'm using HttpClient version 4.3.3 which has no method httpClient.getCookieStore() anymore.

도움이 되었습니까?

해결책

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

다른 팁

version 4.5.2 You can use this code:

List<Cookie> cookies = ((CookieStore)localContext.getAttribute(HttpClientContext.COOKIE_STORE)).getCookies();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top