Wednesday, January 21, 2015

Android Setting Cookie to WebView

In order to set the cookie into the Android WebView, below code can be used.

                        CookieManager.getInstance().setAcceptCookie(true);
                        CookieManager.getInstance().setCookie("myhttp.info","testcookie=cookietest");

                        webView.setWebViewClient(new WebViewClient());
                        webView.loadUrl("http://myhttp.info/");


the web page http://myhttp.info/ is a good tool to know what headers the request is containing.
In the above code, it is trying to pass the cookie as cookietest for the key testcookie. The appearance of this page is something like below



References:
http://myhttp.info/

No comments:

Post a Comment