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