Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Read http header in qt webengine

Read http header in qt webengine

Scheduled Pinned Locked Moved Unsolved QtWebEngine
8 Posts 2 Posters 2.9k Views
  • 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 Offline
    A Offline
    Arhk
    wrote on 9 May 2018, 06:07 last edited by
    #1

    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
    0
    • M Offline
      M Offline
      mpergand
      wrote on 9 May 2018, 19:25 last edited by mpergand 5 Sept 2018, 20:45
      #2

      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
      0
      • A Offline
        A Offline
        Arhk
        wrote on 10 May 2018, 10:08 last edited by
        #3

        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 10 May 2018, 11:36
        0
        • A Arhk
          10 May 2018, 10:08

          Thanks for your answer,but i want read http header when a page is loaded into webengine view and qnerwork is not accessible.

          M Offline
          M Offline
          mpergand
          wrote on 10 May 2018, 11:36 last edited by mpergand 5 Oct 2018, 11:37
          #4

          @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
          1
          • A Offline
            A Offline
            Arhk
            wrote on 11 May 2018, 15:57 last edited by
            #5

            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
            0
            • M Offline
              M Offline
              mpergand
              wrote on 11 May 2018, 16:48 last edited by mpergand 5 Nov 2018, 16:48
              #6

              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
              1
              • A Offline
                A Offline
                Arhk
                wrote on 13 May 2018, 05:30 last edited by
                #7

                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
                0
                • M Offline
                  M Offline
                  mpergand
                  wrote on 13 May 2018, 10:25 last edited by
                  #8

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

                  1 Reply Last reply
                  1

                  3/8

                  10 May 2018, 10:08

                  5 unread
                  • Login

                  • Login or register to search.
                  3 out of 8
                  • First post
                    3/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved