17

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,240
  • 1
  • 14
  • 27

2 Answers2

1

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
  • 1,415
  • 2
  • 12
  • 24
  • This only works for XMLHttpRequest requests. Not for anything else. – AlanSTACK Oct 09 '22 at 04:47
  • It's supposed to work also for fetch calls as well as form submissions. Can you please file an issue on GitHub if you find a page where it doesn't work? – user3738870 Oct 09 '22 at 14:34
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