Javafx webview http response data

2020-03-06 05:13发布

问题:

Is it possible to read the http request and response data from pages loading inside webview. What i want to do is get the binary data from a response after user clicks on a link inside the page in webview. Any help or clue would be greatly appreciated

回答1:

Create your own URLStreamHandlerFactory initialized by URL.setURLStreamHandlerFactory which generates a URLStreamHandler that wraps the standard http and https URLStreamHandlers to intercept their traffic before forwarding.

Some of the concepts are explained in A New Era for Java Protocol Handlers whitepaper.

Another option is to listen to the WebEngine.location property and open a separate connection to a server to retrieve and process the binary data as needed. An example of this approach is the pdf handling code for the willow web browser.