Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Is there a way to intercept JavaScript methods that result in HTTP requests? I know there is the JavaScriptInterface. I use this to register an event listener that listens for clicks on submit buttons and creates POST requests for this. At least this works.

My current problem is that I cannot intercept other requests originating from JavaScript like jQuery. I have to support web services I can't control. I have to intercept all communication requests from the WebView and delegate it to an HttpClient (due to better supportflexibility when it comes to authentication and SSL certificate handling). The result of the HttpClient are passed back to the WebView. I use shouldInterceptRequest(), onLoadResource() and other methods to intercept requests. I also use the above JavaScriptInterface to detect submits and create POST requests from it.

Currently I try to fix one service that isn't showing some chart data which is loaded using jQuery and other JS libraries. Some JS functions are called to load data asynchronously and present it in a chart. Ultimateley a jquery function send() is called and a POST request is created. Unfortunately this POST request seems to be automatically handled by the WebView. I don't see any log messages and the chart area remains empty. With my code only the callback shouldInterceptRequest() is called but without the POST parameters.

Is there any way to detect and intercept POST requests on a WebView without registering for click events on submit buttons by injecting JavaScript. Also, there are countless other JS functions that can create a POST request I cannot know beforhand. Any help is appreciated.

Best regards Bjoern

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.