开发者

Mark Cookies as Secured in Android Webview

开发者 https://www.devze.com 2023-03-29 03:22 出处:网络
I need to mark the cookies as secured when I use them with CookieManager in Android WebView. How can 开发者_如何学运维I do that?Try this.

I need to mark the cookies as secured when I use them with CookieManager in Android WebView. How can 开发者_如何学运维I do that?


Try this.

CookieSyncManager.getInstance().sync();
String cookie = CookieManager.getInstance().getCookie(DOMAIN_NAME+COOKIE_PATH);
        BasicCookieStore cookieJar = new BasicCookieStore();
        if (!cookie.equals("")) {
            String[] cookies = cookie.split(";");
            for (int i = 0; i < cookies.length; i++) {
                String[] nvp = cookies[i].split("=");
                BasicClientCookie c = new BasicClientCookie(nvp[0], nvp[1]);
                c.setDomain(DOMAIN_NAME);
                c.setPath(COOKIE_PATH);
                c.setSecure(true);
                cookieJar.addCookie(c);
            }
        }
0

精彩评论

暂无评论...
验证码 换一张
取 消