14

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!

Karl Jamoralin
  • 1,121
  • 1
  • 16
  • 26

2 Answers2

0

This is the only solution I found. It is an interesting hack. I have converted to work with Xamarin.Android so I am sure it will work for Native Android.

https://stackoverflow.com/a/45655940/4880012

Emmanuel Vazquez
  • 93
  • 1
  • 1
  • 9
0

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!

user3738870
  • 412
  • 5
  • 16