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. Injecting custom headers in QtWebEngineView
Forum Updated to NodeBB v4.3 + New Features

Injecting custom headers in QtWebEngineView

Scheduled Pinned Locked Moved Unsolved QtWebEngine
3 Posts 2 Posters 2.4k 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.
  • V Offline
    V Offline
    valeryz
    wrote on 11 Oct 2016, 18:12 last edited by p3c0 10 Dec 2016, 05:48
    #1

    Hello,

    I was wondering if it possible to inject custom headers with QtWebEngineView. I am loading a webview and initial http request should have a custom header. Before upgrading to qt5.7, I would inject them during QNetworkAccessManager.createRequest(). Now, since QNetworkAccessManager can not be attached to QWebEngineView, it's not an option. I've read QtWebEngineView and QtWebPage documentation to see if I could find something relevant, but couldn't find a solution...
    Here are relevant parts of the code:

    void webPage::start()
    {
        m_webView->stop();
        QString m_startUrl = "sample.com"
        m_webView->load(QUrl::fromUserInput(m_startUrl));
        m_webView->show();
    }
    

    I would like to insert a custom header only once when performing
    m_webView->load(QUrl::fromUserInput(m_startUrl));

    Any suggestions are appreciated

    R 1 Reply Last reply 12 Oct 2016, 05:55
    0
    • V valeryz
      11 Oct 2016, 18:12

      Hello,

      I was wondering if it possible to inject custom headers with QtWebEngineView. I am loading a webview and initial http request should have a custom header. Before upgrading to qt5.7, I would inject them during QNetworkAccessManager.createRequest(). Now, since QNetworkAccessManager can not be attached to QWebEngineView, it's not an option. I've read QtWebEngineView and QtWebPage documentation to see if I could find something relevant, but couldn't find a solution...
      Here are relevant parts of the code:

      void webPage::start()
      {
          m_webView->stop();
          QString m_startUrl = "sample.com"
          m_webView->load(QUrl::fromUserInput(m_startUrl));
          m_webView->show();
      }
      

      I would like to insert a custom header only once when performing
      m_webView->load(QUrl::fromUserInput(m_startUrl));

      Any suggestions are appreciated

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 12 Oct 2016, 05:55 last edited by
      #2

      @valeryz
      Use QWebEngineUrlRequestInterceptor and QWebEngineUrlRequestInfo::setHttpHeader()

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • V Offline
        V Offline
        valeryz
        wrote on 12 Oct 2016, 14:55 last edited by
        #3

        Thank you so much! That should do it!

        1 Reply Last reply
        0

        1/3

        11 Oct 2016, 18:12

        • Login

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