Issue
What I am trying to achieve is to autologin to a https website by setting a token as a cookie.
( It works on android chrome browser but not in application webview )
Basically I am facing two issue while loading https url into web view with cookie set
Issue 1
I am getting following log message.
Failed to validate the certificate chain, error: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
I tried overriding onReceivedSslError
and called handler.proceed();
as below.
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
Log.d(TAG, "==> " + error.toString());
handler.proceed();
}
But still I see white page ( I am assuming Its happening because of certificate issue. )
Issue 2
I have got a login url with me ( e.g https://www.abc.com/login.html )
What I am trying to achieve is auto login into web view by setting a cookie.
CookieSyncManager.createInstance(webView.getContext());
CookieManager cookieManager = CookieManager.getInstance();
CookieManager.getInstance().setAcceptCookie(true);
String token = PreferenceHelper.loadTokenFromPreference(this);
String sessionCookie = "staging=" + token;
cookieManager.setCookie("https://www.abc.com/aaa/",
sessionCookie);
CookieSyncManager.getInstance().sync();
SystemClock.sleep(1000);
But still I am not able to auto login.Rather I am seeing the white page.
What I am not sure now is exactly where I am making a mistake.
cookieManager.setCookie
requires first argument as a url for which cookie needs to set,I am not sure exactly which url i need to give it ?
Can anyone suggest me the right approach to get it working ?
Thanks
Solution
Well after searching for quite a while I finally got the solution.
I had to add following lines to get it working.
webView.getSettings().setAppCachePath(appCachePath);
webView.getSettings().setAppCacheEnabled(true);
Answered By - Vipul
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.