Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebViewClient: How To Get POST request body

I have a requirement to get the request body from a POST request in our WebView. It doesn't look like the WebResourceResponse in WebViewClient.shouldInterceptRequest has a method for this. Has anyone had the same issue and how did you worked around it?

Thanks!

like image 283
Karl Jamoralin Avatar asked Dec 18 '25 23:12

Karl Jamoralin


1 Answers

I have created a library that aims to capture all data of all HTTP requests sent from Android WebViews, including the request body.

Using this library, you can easily read the request body like this:

    override fun shouldInterceptRequest(
        view: WebView,
        webViewRequest: WebViewRequest
    ): WebResourceResponse? {
        Log.i("RequestInspectorWebView", "Here's the body: ${webViewRequest.body}")
        return super.shouldInterceptRequest(view, webViewRequest)
    }

I hope this helps!

like image 76
user3738870 Avatar answered Dec 21 '25 13:12

user3738870