URL url = new URL("HTTP://km.oa.com");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setInstanceFollowRedirects(false);
CookieManager manager = new CookieManager();
manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(manager);
con.getInputStream();
System.out.println(con.getResponseCode());
CookieStore store = manager.getCookieStore();
List<HttpCookie> cookie = store.getCookies();
System.out.println(cookie);
for (HttpCookie coo : cookie) {
System.out.println(coo);
}
String str = con.getHeaderField("set-cookie");
System.out.println(str);
胡说叔叔
相关分类