WebView Cookie Settings

Source: Internet
Author: User

Cookiesyncmanager.createinstance (_context);
Cookiemanager manager = Cookiemanager.getinstance ();
Manager.setacceptcookie (TRUE);
Manager.removesessioncookie ();
StringBuilder builder = null;
for (HttpCookie cookie:allcookies) {
Builder = new StringBuilder ();
Builder.append (Cookie.getname ());
Builder.append ("=");
Builder.append (Cookie.getvalue ());
Builder.append ("; Path= ");
Builder.append (Cookie.getpath ());
Builder.append ("; Domain= ");
Builder.append (Cookie.getdomain ());
Manager.setcookie (Xidibuyconstants.domain_xidibuy,
Builder.tostring ());
LOG.E (TAG, "Cookie:" + builder);
}
Cookiesyncmanager.getinstance (). sync ();

Attention:

1.//Manager.removesessioncookie (); In some versions of Android, the cookie will fail to save. Known 4.4 no problems, 4.3 have problems.

2. The server sends a cookie and sometimes wants to send some cookie that is deleted to overwrite the existing cookie.

However, in order to save time, some servers will send a cookie that contains only key and value, and does not contain path and domain. In this case, WebView will consider it to be two cookies and will not overwrite the existing cookie.

WebView When you save a cookie, it must be overwritten by the same key,path and domain.

So make sure that the server sends a cookie that contains key,path,domain otherwise it needs to be handled manually when it is saved.

WebView Cookie Settings

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.