最近在做一个项目,有一个模块为了减轻工作量,直接用webview显示网页的内容,但是要在登陆状态下请求的,所以需要让webview带着cookie,cookie本人存在了本地,通过下面这段代码设置
CookieSyncManager.createInstance(this); CookieManager manager = CookieManager.getInstance(); manager.setAcceptCookie(true); manager.removeSessionCookie(); manager.setCookie("xxxx", app.getCookie()); CookieSyncManager.getInstance().sync(); mWebView = (WebView) findViewById(R.id.rank_webview); mWebView.setHorizontalScrollBarEnabled(false); mWebView.getSettings().setJavaScriptEnabled(true); mWebView.setWebChromeClient(new WebChromeClient()); mWebView.loadUrl("xxxx");
xxx是请求的网页,但是结果却是一直不成功。app.getCookie()的内容是OFFERME=itbgstq2p6jiud37b3dm98poo2; path=/splash=Pdk6Oapz3DOudldaT1fdp4y4IOOyYEadZ0EyQtkJlQNd%2B8CXC51QPlJ0LHR8Pmb1sm3WkjuRFoxSNm%2FjoRXx3Q%3D%3D; expires=Sat, 05-Sep-2015 03:20:00 GMT; Max-Age=31536000; path=/; httponlybannerads=h8B5toOffEn0CWvAWfNp%2FaQRIPyDZtufs3pZFhMX48%2BkzCFQYOOdKRKOqHqTyOify4Vd3Src4Eo4Rn7z1uO2Gg%3D%3D; expires=Sat, 05-Sep-2015 03:20:00 GMT; Max-Age=31536000; path=/; httponly
求达人指点。
解决方案