Why can't Java CookieManager get the cookie,? when I get the response head, I can see the set-cookie head.

topic description

sources of topics and their own ideas

related codes

/ / Please paste the code text below (do not replace the code with pictures)
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);

what result do you expect? What is the error message actually seen?

Mar.29,2021

needs to be in

manager.getCookieStore();openConnection();getInputStream();
HttpClientcookie
CookieStore cookieStore = new BasicCookieStore();
httpClient = HttpClients.custom().setDefaultCookieStore(cookieStore).build();
List<Cookie> cookies = cookieStore.getCookies();
Menu