Read http header in qt webengine
-
wrote on 9 May 2018, 06:07 last edited by
Hello,
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.
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.
Thanks -
wrote on 9 May 2018, 19:25 last edited by mpergand 5 Sept 2018, 20:45
Hi,
As far as i know Chrome implements its own network stack not accessible from Qt.
Anyway, if your only goal is to read http headers, QNetworkManager allows to do that pretty easely.
Connect the QNetworkReply to metaDataChanged() signal, that's all.
The headers are accessible through the headers/rawheaders methods of the reply.
See Qt docs for more infos. -
wrote on 10 May 2018, 10:08 last edited by
Thanks for your answer,but i want read http header when a page is loaded into webengine view and qnerwork is not accessible.
-
Thanks for your answer,but i want read http header when a page is loaded into webengine view and qnerwork is not accessible.
wrote on 10 May 2018, 11:36 last edited by mpergand 5 Oct 2018, 11:37@Arhk said in Read http header in qt webengine:
and qnerwork is not accessible.
Why not ?
I've done a download manager based on QNetworkManager on a QWebEngine app, i'm using meta infos as filename, file length etc, and no issues so far.Except doing the request yourself, I have no clue.
It's not a big deal, only a few lines of code is needed.
Why not have a try ? -
wrote on 11 May 2018, 15:57 last edited by
it,s correct but i want to add a method into demo browser project to print http headers. In demo browser webenginepage is used to load page and i cant use qnetworkmanager.
Can you give me some codes which implement my method using qnetwork in demo browser project. -
wrote on 11 May 2018, 16:48 last edited by mpergand 5 Nov 2018, 16:48
Looking at the demobrowser sources, it turns out it's pretty easy since demobrowser use a QNetworkManager itself !
In the load(url) method of WebView.cpp do:
void WebView::loadUrl(const QUrl &url) { m_initialUrl = url; load(url); QNetworkReply *reply = BrowserApplication::networkAccessManager()->get(QNetworkRequest(url)); QObject::connect(reply, &QNetworkReply::metaDataChanged, [reply] () { qDebug()<<reply->url(); qDebug()<<reply->rawHeaderPairs(); reply->abort(); reply->deleteLater(); } ); }
-
wrote on 13 May 2018, 05:30 last edited by
thanks for your reply but I dont want to create a new request to just get header field. I want to get it directly from qwebengineurlrequestinfo object in Qwebenineurlrequestinceptor class. I need to use the http headers and take a decision to set another header field.
-
wrote on 13 May 2018, 10:25 last edited by
Starting with Qt 5.9 there's a new QWebEngineHttpRequest that seems allowing to read/set headers.
3/8