WebView with custom HTTP client

My task is to load the website into WebView via HTTPS with an unsupported TLS cipher for Android vanilla. Right now, as a proof of concept, I implemented an apache http client that is able to perform http requests to such resources.

What is the best approach for WebView to use my client implementation to fulfill all network requests?

+6
source share
2 answers

Starting with Android 5.0 (API 21+), you can use WebViewClient.shouldInterceptRequest(WebView, WebResourceRequest) to intercept web requests with full information and execute them using a custom HTTP client.

Thanks @Stan for the tip.

0
source

Actually, the accepted answer is incorrect. You do not receive complete information; what is missing are request bodies.

This way you can implement GET or HEAD requests just fine, but POST requests are more complicated.

I have not seen a good solution yet. The one I came across uses the JavaScript inserted in the page to collect POST data, pass it to Java through the https://developer.android.com/guide/webapps/webview.html#BindingJavaScript binding, and then makes a request to Java

Unfortunately, WebView will try to execute the same request again, so you need to add more hackers to make it work.

+1
source

Source: https://habr.com/ru/post/949723/


All Articles