Stack Exchange
419 page Expired when navigate in webview in android
I am using WebView. When i navigate WebView, it shows 419 | page Expired. I have used the below code.
          @SuppressLint("SetJavaScriptEnabled")
        fun loadWebview(url:String){
    
            var  webView:WebView = findViewById(R.id.webView)
            //begin new
            val webSettings = webView.settings
            webSettings.javaScriptEnabled = true
            webSettings.allowFileAccess = true
            webSettings.allowContentAccess = true
            webSettings.databaseEnabled = true
            webSettings.javaScriptCanOpenWindowsAutomatically = true
    
            //improve webView performance
    
            webView.settings.setRenderPriority(WebSettings.RenderPriority.HIGH)
            webView.settings.cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK
            webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
            webView.scrollBarStyle = View.SCROLLBARS_INSIDE_OVERLAY
            webSettings.domStorageEnabled = true
            webSettings.layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS
            webSettings.useWideViewPort = true
            webSettings.savePassword = true
            webSettings.saveFormData = true
            webSettings.setEnableSmoothTransition(true)
    
            webSettings.setDomStorageEnabled(true);
    
            webView.getSettings().setDomStorageEnabled(true);
            if (Build.VERSION.SDK_INT >= 21) {
                webSettings.mixedContentMode = 0
                webView.setLayerType(View.LAYER_TYPE_HARDWARE, null)
            } else if (Build.VERSION.SDK_INT >= 19) {
                webView.setLayerType(View.LAYER_TYPE_HARDWARE, null)
            } else {
                webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null)
            }
            webView.webChromeClient = WebChromeClient()
    
            CookieSyncManager.createInstance(this)
            CookieSyncManager.getInstance().startSync()
            val cookieManager: CookieManager = CookieManager.getInstance()
            cookieManager.setAcceptCookie(true)
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                CookieManager.getInstance().setAcceptThirdPartyCookies(webView, true)
            }
    
            webView.loadUrl(url)
    
    
        }

What is wrong with my code? Please help me.

It might be a problem with your internet connection !!
There are two steps you can take to resolve this issue:

Check your internet connection.
Clear Webview cache.

For clear cache:
webView.clearCache(true);
webView.clearHistory();

I hope this can solve your problem.

Thanks, I switch the data connection which is working fine. But I am using wifi. Other apps are running well. Is there any idea of the problem?
