How to parse a cookie string

后端 未结 9 1908
眼角桃花
眼角桃花 2020-12-08 04:47

I would like to take a Cookie string (as it might be returned in a Set-Cookie header) and be able to easily modify parts of it, specifically the expiration date.

I s

9条回答
  •  误落风尘
    2020-12-08 04:54

    CookieManager cookieManager = new CookieManager();
            CookieHandler.setDefault(cookieManager);
            HttpCookie cookie = new HttpCookie("lang", "en");
            cookie.setDomain("Your URL");
            cookie.setPath("/");
            cookie.setVersion(0);
    
            cookieManager.getCookieStore().add(new URI("https://Your URL/"), cookie);
            List Cookies =  cookieManager.getCookieStore().get(new URI("https://Your URL/"));
            String s = Cookies.get(0).getValue();
    

提交回复
热议问题