How to read response body in JBCefBrowser?
已回答
Hi, I'm trying to read response body that occurs in web.
I can see that JBCefBrowser provides with the environment of load certain web page.
I found out that CefResourceRequestHandler can observe request and response.
(https://github.com/JetBrains/jcef/blob/master/java/org/cef/handler/CefResourceRequestHandler.java)
But CefResponse, which is a parameter of the methods in CefResourceRequestHandler, doesn't provide any information about response body. (https://github.com/JetBrains/jcef/blob/dev/java/org/cef/network/CefResponse.java)
Could you help me to read response body in JBCefBrowser?
Thanks
请先登录再写评论。
This handler can intercept the request, but it doesn't observe the responses by itself. There is no option to mirror the responses with the body that receives the browser.
However, the handler can return an instance of
CefResourceHandler
for a request, that allows to execute or fake the response. So you can get the request data, execute the request by yourself, intercept the response and forward it to the browser.For example in this handler, you can simply read a file, fill out the HTTP headers as you want and stream the file content to the browser. The browser will “think” that it downloaded it from the network.
Thank you for fixing my wrong understanding. Your comment helped me alot!