Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved Read http header in qt webengine

    QtWebEngine
    2
    8
    2222
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Arhk 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

      1 Reply Last reply Reply Quote 0
      • M
        mpergand last edited by mpergand

        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.

        1 Reply Last reply Reply Quote 0
        • A
          Arhk 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.

          M 1 Reply Last reply Reply Quote 0
          • M
            mpergand @Arhk last edited by mpergand

            @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 ?

            1 Reply Last reply Reply Quote 1
            • A
              Arhk 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.

              1 Reply Last reply Reply Quote 0
              • M
                mpergand last edited by mpergand

                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();
                        } );
                }
                
                1 Reply Last reply Reply Quote 1
                • A
                  Arhk 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.

                  1 Reply Last reply Reply Quote 0
                  • M
                    mpergand last edited by

                    Starting with Qt 5.9 there's a new QWebEngineHttpRequest that seems allowing to read/set headers.

                    1 Reply Last reply Reply Quote 1
                    • First post
                      Last post