Different questions about httpclient and webview sessions of Android
Source: Internet
Author: User
When developing a project, we encountered such a problem. The logon interface was implemented using the android native UI. After successful login, we will jump to the webview to load sencha touch data, however, when loading data from the webview to the backend, we found that the session at this time is different from the session at login, so we could not get the data. For this reason, Google has found a method in stackoverflow for a long time, post the original address here: the key points are in the following code: Private defaulthttpclient httpclient; public static cookie = NULL; // after login list <cookie> cookies = httpclient. getcookiestore (). getcookies (); If (! Cookies. isempty () {for (INT I = 0; I <cookies. size (); I ++) {cookie = cookies. get (I) ;}/// note: the following code is written in the webview activity // ------- Web browser activity cookie sessioncookie = MyApp. cookie; // The cookie here is the cookie cookiesyncmanager saved above. createinstance (this); cookiemanager = cookiemanager. getinstance (); If (sessioncookie! = NULL) {cookiemanager. removesessioncookie (); string cookiestring = sessioncookie. getname () + "=" + sessioncookie. getvalue () + "; domain =" + sessioncookie. getdomain (); cookiemanager. setcookie (MyApp. domain, cookiestring); cookiesyncmanager. getinstance (). sync (); not much to mention, mainly after the login is successful, save the cookie, and then setcookie in webview.
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.