在app登录的时候需要把cookie保存下来
String cookieFields = response.getHeaders("Set-Cookie")[0] .getValue(); String cookie = cookieFields.split(";\\s*")[0]; HttpGet nextGet = new HttpGet(url); nextGet.setHeader("Cookie", cookie); CookieSyncManager.createInstance(MainActivity.this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.setCookie("http://112.124.12.46", cookieFields);//cookies是在HttpClient中获得的cookie CookieSyncManager.getInstance().sync();
在webview 页面需要同步cookie
CookieSyncManager.createInstance(WebViewActivity.this); CookieManager.getInstance();
在app登录过后,webview页面使用app登录cookie直接进入,布布扣,bubuko.com
时间: 2024-10-22 23:21:35