I want to capture server http response in qt demo browser and check the header fields. How to implement this using qt webengine? I also saw QWebEngineUrlRequestInterceptor but using this class we cant read http header fields.
2 Answers
you need to run your browser with remote debug to enable chrome dev tools: set 'QTWEBENGINE_REMOTE_DEBUGGING' = port , in QT environment . after that from other qtwebengine instance connect to localhost:port , then you can use all chromium dev tools ,monitor/manipulate all network traffic .
If you do not need visualization , then need to make your own client for chromium dev tools protocol(they have pretty good manuals) . Collect all responses in way you prefer , in responses look for method='Network.responseReceived' , with available selector (for example response['params']['response']['url'] ) , then you will have in you response response['params']['requestId'] , with requestId you can do Network.getResponseBody(requestId=response['params']['requestId']) .

- 91
- 2
- 3
-
Thanks for your reply. But i want to read http headers in qt source code. For example, i want to add a method in demo browser that print http headers of all requests. There is no need to capture traffic or any tools as dev tools or wireshark. – alireza Apr 10 '18 at 05:44
I think is not possible. You can use a QWebEngineUrlRequestInterceptor to intercep your requests. Here I'm adding a bearer token for all requests, but I think is impossible to read headers
void customInterceptor ::interceptRequest(QWebEngineUrlRequestInfo &info)
{
info.setHttpHeader("Authorization", ("Bearer " + m_token).toLocal8Bit());
info.setHttpHeader("accept-language", Translator::instance()->getCurrentLang().toLocal8Bit());
}

- 992
- 9
- 14