牛骨文教育服务平台(让学习变的简单)
博文笔记

android webView携带sessionid

创建时间:2016-05-09 投稿人: 浏览次数:1819

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();
		}


声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。