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. How To Get HTTP Status Codes From QWebEngineView?
Forum Updated to NodeBB v4.3 + New Features

How To Get HTTP Status Codes From QWebEngineView?

Scheduled Pinned Locked Moved Unsolved QtWebEngine
3 Posts 3 Posters 2.3k 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.
  • T Offline
    T Offline
    tshoats
    wrote on last edited by
    #1

    Hello, sorry if i posted twice, just found out theres a QWebEngine forum section. I've been looking through the docs to find a way to return the http status codes from a QWebEngineView after loading a page, and making a request. I understand that QWebEngineView does not interact with QNetWorkAccessManager which would make this a breeze to accomplish. So is there any other way to get the HTTP status code from a request using QWebEngineView?? I tried multiple ways including RequestInterceptor. Below is a snippet of my attempt using RequestInterceptor, but its not giving me actual HTTP Status codes, just constant values, which is what I dont want..

    //your code here   
            /*************requestinterceptor.h**************/
    #ifndef REQUESTINTERCEPTOR_H
    #define REQUESTINTERCEPTOR_H
    
    #include <QWebEngineUrlRequestInterceptor>
    #include <QWebEngineUrlRequestInfo>
    #include <QDebug>
    #include <QUrl>
    
    class RequestInterceptor : public QWebEngineUrlRequestInterceptor
    {
    public:
      explicit RequestInterceptor(QObject * parent = Q_NULLPTR);
      virtual void interceptRequest(QWebEngineUrlRequestInfo & info) Q_DECL_OVERRIDE;
    };
    #endif // REQUESTINTERCEPTOR_H
    
    /*************requestinterceptor.cpp***************/
    
    #include "requestinterceptor.h"
    
    RequestInterceptor::RequestInterceptor(QObject * parent)
      :QWebEngineUrlRequestInterceptor(parent){}
    
    void RequestInterceptor::interceptRequest(QWebEngineUrlRequestInfo & info)
    {
      QString rsrct = "";
      switch(info.resourceType()){
          case 0:rsrct="ResourceTypeMainFrame = 0, --> top level page";break;
          case 1:rsrct="ResourceTypeSubFrame, --> frame or iframe";break;
          case 2:rsrct="ResourceTypeStylesheet, --> a CSS stylesheet";break;
          case 3:rsrct="ResourceTypeScript, --> an external script";break;
          case 4:rsrct="ResourceTypeImage, --> an image (jpg/gif/png/etc)";break;
          case 5:rsrct="ResourceTypeFontResource, --> a font";break;
          case 6:rsrct="ResourceTypeSubResource, --> an other subresource.";break;
          case 7:rsrct="ResourceTypeObject, --> an object (or embed) tag for a plugin,";break;
          case 8:rsrct="ResourceTypeMedia, --> a media resource.";break;
          case 9:rsrct="ResourceTypeWorker, --> the main resource of a dedicated worker.";break;
          case 10:rsrct="ResourceTypeSharedWorker, --> the main resource of a shared worker.";break;
          case 11:rsrct="ResourceTypePrefetch, --> an explicitly requested prefetch";break;
          case 12:rsrct="ResourceTypeFavicon, --> a favicon";break;
          case 13:rsrct="ResourceTypeXhr, --> a XMLHttpRequest";break;
          case 14:rsrct="ResourceTypePing, --> a ping request for <a ping>";break;
          case 15:rsrct="ResourceTypeServiceWorker, --> the main resource of a service worker.";break;
          case 16:rsrct="ResourceTypeUnknown";break;
    
          default : rsrct="Unknown type";break;
      }
    
    qDebug()<<"\t"<<Q_FUNC_INFO<<":\n\t\t" << "WebUrlRequestInterceptor::interceptRequest    " <<info.requestMethod()
           <<"\r\n  "<<info.requestUrl()<<"   "<<rsrct      <<"\r\n";
    
    }
    
    /*************mainwindow.cpp***************/
      const QUrl url("http://google.com");
      view = new WebView();
      view = new QWebEngineView();
      interceptor = new RequestInterceptor(view);
      profile = new QWebEngineProfile(view);
      profile->setRequestInterceptor(interceptor);
      page = new QWebEnginePage(profile,view);
      view->setPage(page);
    
    1 Reply Last reply
    0
    • G Offline
      G Offline
      Gustav E
      wrote on last edited by
      #2

      I have the same issue. Did you find a solution for this?

      JonBJ 1 Reply Last reply
      0
      • G Gustav E

        I have the same issue. Did you find a solution for this?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @Gustav-E
        Does the (rather terse) answer at https://stackoverflow.com/a/53516333/489865 help you?
        Otherwise you might have to resort to https://forum.qt.io/topic/80372/qml-webengineview-does-not-return-http-page-errors/2# ?

        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