android webView携带sessionid
webView中携带session传递给服务器端
SharedPreferences cookies=getSharedPreferences("Login",Activity.MODE_PRIVATE); webView = (WebView) findViewById(R.id.webview); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { CookieSyncManager.createInstance(this); } CookieManager cookieManager = CookieManager.getInstance(); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { cookieManager.removeAllCookie(); }else{ cookieManager.removeSessionCookies(new ValueCallback<Boolean>() { @Override public void onReceiveValue(Boolean value) { } }); } cookieManager.setAcceptCookie(true); String cookieString = cookies.getString("cookiesname","") + "=" + cookies.getString("cookies_values",""); cookieManager.setCookie(ApplicationParams.OPENSPORTYRL, cookieString);//cookies是在HttpClient中获得的cookie if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { CookieSyncManager.createInstance(this).sync(); }else{ cookieManager.setAcceptThirdPartyCookies(webView, true); cookieManager.flush(); }
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了