标签:
因要app中使用webview访问一个网站,但是app与服务器的沟通是使用HttpUrlConnection来完成的,
private class LoadWebViewTask extends AsyncTask<Void, Void, Void> { CookieManager cookieManager; @Override protected void onPreExecute() { CookieSyncManager.createInstance(TestWebActivity.this); cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(true); cookieManager.removeSessionCookie(); //移除上一次的session } @Override protected Void doInBackground(Void... params) { ThreadUtils.sleep(1500); //等待cookieManager处理完毕 return null; } @Override protected void onPostExecute(Void result) { cookieManager.setCookie("test.com", "ASP.NET_SessionId=" + businessLogicManager.getSessionId()); //设置cookie CookieSyncManager.getInstance().sync(); //同步 webView.loadUrl("http://test.com"); } }
标签:
原文地址:http://www.cnblogs.com/fairy520wch/p/4668942.html