I'm having some trouble getting my webview to work properly
The webview is supposed to display this url https://mcdonalds.de/deinfeedback , but whenever I try to load it my onReceivedHttpError
method returns me an
403 Forbidden
Error. It works just fine for other urls like https://www.google.com, but i can't seem to make it work for this one. At first I thought it had something to do with the ssl certificates, however my WebViewClient's onReceiveSslError
is never called. I then tried to change my user agent string to the same one I have on my mobile browser but it still returned me the same 403 error
This is the part in my onCreate where I deal with the WebView
webViewDisplay.settings.builtInZoomControls = true
webViewDisplay.settings.displayZoomControls = false
webViewDisplay.settings.domStorageEnabled = true
webViewDisplay.settings.javaScriptEnabled = true
webViewDisplay.settings.javaScriptCanOpenWindowsAutomatically = true
webViewDisplay.webViewClient = MyWebClient()
webViewDisplay.loadUrl(resources.getString(R.string.web_activation_url_main)) //https://www.mcdonalds.de/deinfeedback
And this is my WebViewClient
inner class MyWebClient : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest): Boolean {
Log.v(TAG, "Overriding Url to ${request.url.toString()}")
return false //continues loading
}
override fun onReceivedSslError(view: WebView?, handler: SslErrorHandler, error: SslError?) {
Log.v(TAG, "Ssl Error")
handler.proceed() //handle error
}
override fun onReceivedHttpError(view: WebView?, request: WebResourceRequest?, errorResponse: WebResourceResponse) {
Log.v(TAG, "Http Error ${errorResponse.statusCode} ${errorResponse.reasonPhrase}")
super.onReceivedHttpError(view, request, errorResponse)
}
}
I hope somebody can help me with this
Edit:
The 403 Error was not the issue. I had set the height of my layout to wrap_content
which makes the webView wrap itself on some sites. Changing it to match_parent
fixed it.
Credit for this goes to Dani