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);
}
}
精彩评论