Intercept POST requests in a WebView Intercept POST requests in a WebView android android

Intercept POST requests in a WebView


I was facing the same issue a few days ago.

So I built a library that solves it:

https://github.com/KonstantinSchubert/request_data_webviewclient

It is a WebViewClient with a custom WebResourceRequest that contains the POST/PUT/... payload of XMLHttpRequest requests.

It only works for these though - not for forms and other kind of request sources.

The hack works, basically, by injecting a script into the HTML that intercepts XMLHttpRequest calls. It records the post/put/... content and sends it to an android.webkit.JavascriptInterface. There, the request is stashed until the shouldInterceptRequest method is called by Android ...


I have one of my answers on above thread http://code.google.com/p/android/issues/detail?id=9122

Please see comment#31

Some of the caveats of my solution I see are:

  1. Putting a dependency on xmlhttprequest prototype which has different implementation for different webkits.
  2. Security issue in sending data for post requests in URL. But I guess you can solve that through some encryption mechanism.
  3. URL length issue for some of the browsers if you big data to post

Apart from that, I found this github repo which seems to be solving this problem in another hacky way. I looked into the code but didn't get time to implement and test it. But worth giving a try.