Android WebView losing Cookies in redirects

Viewed 3876

My problem is with WebView dealing with redirects and custom cookies.

I do following:

  1. Create instances of CookieSyncManager and CookieManager in application create
  2. Call sCookieManager.setAcceptCookie(true); in static section in util class
  3. Call sCookieManager.setCookie(url, value); sCookieSyncManager.sync();
  4. And finally mWebView.loadUrl

What's happening in server side is that it first gets the correct cookie I have set, runs some redirect and cookie seems to be lost. Any ideas, what I am doing wrong here?

I've tried running setCookie - sync in another thread giving some delay and then loadUrl but it didn't help.

All similar posts seem to have solutions which are not working.

Thanks.

UPDATE:

I noticed that using setCookie to give multiple Cookies like for example:

setCookie("MyCookie=value; Domain=mydomain.com; Path=/; Secure; HttpOnly; MySecondCookie=value2....)"

Only the first one is applied, and then it's gone when server runs redirects on it's own domain. This issue can be fixed settings custom cookies one in a time in a loop.

I have temporarily added handler.proceed(); in onReceivedSslError and I can see from the logs that it's triggering just before web site redirects and Cookie is lost in on next pages onPageFinished, could there be some connection between secure cookies and invalid certificate chains?

1 Answers
Related