0

Getting header fields from a URLConnection doesn't get session cookies for me.

When I use CookieManager I can get session cookies from a URL:

CookieManager manager = new CookieManager();
manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(manager);

URLConnection con = url.openConnection();
con.getContent();

CookieStore cookieJar = manager.getCookieStore();
List<HttpCookie> cookies = cookieJar.getCookies();

This is fine, but I need to send a POST request. So I am writing to the URLConnection's output stream. My question is how to get the session cookies after sending the POST request.

4

1 回答 1

1

尝试使用 URLConnection 对您的第一个和后续请求使用相同的 CookieManager 对象。

于 2012-04-10T15:28:04.957 回答