Android WebView and HttpClient cookie Sync

Source: Internet
Author: User

First, android5.0 implements automatic cookie synchronization between the WebView and the framework without additional action.

5.0 The version requires manual cookie synchronization

Methods are as follows

<pre name= "code" class= "Java" >cookiesyncmanager.createinstance (context);    Cookiemanager Cookiemanager = Cookiemanager.getinstance ();    Cookiemanager.setacceptcookie (true);    Cookiemanager.removeallcookie ();    list<cookie> cookies = new Persistentcookiestore (context). GetCookies ();    for (Cookie cookie:cookies) {      //Note here Why it is presumptuous to write a cookie.getdomain (), rather than the URL as said in the API, similar to baidu.com if it is a domain name, directly set " Baidu.com ",      Cookiemanager.setcookie (<span style=" color: #ff0000; " >cookie.getdomain () </span>,  cookie.getname () + "=" + cookie.getvalue () + "; Domain= "+ cookie.getdomain () +"; Path= "+ Cookie.getpath ());    }    Cookiesyncmanager.getinstance (). sync ();

This involves the knowledge of cookies, when a cookie is set, it detects whether the domain of the cookie is the same as the name of the URL and if the cookie fails to set the inconsistency.

So the URL plays a role in the inside, is to detect domain domains, set the domain name under the request of all the URL of the cookie.

Setting a URL of level two is not easy to understand.

Look at the Google API comments:

  /**     * Sets a cookie for the given URL. Any existing cookies with the same host,     * path and name would be replaced with the new cookie. The cookie being set     * must not has expired and must not is a session cookie, otherwise it     * 'll be ignored.
   
    *     * @param url the URL for which the cookie is set     * @param value the cookie as a string, using the format of the ' Set-cookie '     *              HTTP response Header     *    /public void Setcookie (string url, String value) {        throw New Mustoverrideexception ();    }
   
URL The URL for which the cookie is set, if you do not understand the principle of cookies, which makes the interpretation easier for the reader to understand, just set up this sub-URL of the cookie

Android WebView and HttpClient cookie synchronization

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.