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
QtWS25 Last Chance

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 last edited by p3c0
    #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

    raven-worxR 1 Reply Last reply
    0
    • V valeryz

      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

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on 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 last edited by
        #3

        Thank you so much! That should do it!

        1 Reply Last reply
        0

        • Login

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