Karl Jamoralin
Karl Jamoralin

Reputation: 1260

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!

Upvotes: 17

Views: 9945

Answers (2)

user3738870
user3738870

Reputation: 1632

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!

Upvotes: 6

Emmanuel Vazquez
Emmanuel Vazquez

Reputation: 93

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

Upvotes: 0

Related Questions