Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. How get all HTTP request send by Qt WebKit
QtWS25 Last Chance

How get all HTTP request send by Qt WebKit

Scheduled Pinned Locked Moved Qt WebKit
5 Posts 2 Posters 4.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.
  • B Offline
    B Offline
    BlueRhino
    wrote on last edited by
    #1

    I want get all HTTP request which is send by my application.
    I try to inherit the QNetworkAccessManager .Then I use QWebPage->setNetworkAccessManager().
    But it does not work...............How could I do?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You'll have to be a bit more specific, what doesn't work ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        BlueRhino
        wrote on last edited by
        #3

        [quote author="SGaist" date="1375788633"]Hi and welcome to devnet,

        You'll have to be a bit more specific, what doesn't work ?[/quote]

        Thanks.I will paste my code.
        It is my Widget
        @#include <QNetworkRequest>
        #include <QWebFrame>

        Widget::Widget(QWidget *parent) :
        QWidget(parent),
        ui(new Ui::Widget)
        {
        ui->setupUi(this);
        netWorkAccessManager = new MyNetWorkAccessManager();
        QNetworkRequest *request = new QNetworkRequest(QUrl("http://www.baidu.com"));
        // netWorkAccessManager->get(*request);
        QWebPage *page = new QWebPage();
        page->setNetworkAccessManager(netWorkAccessManager);
        ui->webView->setPage(page);
        ui->webView->load(*request);
        }

        Widget::~Widget()
        {
        delete ui;
        }@

        It is my NetWorkAccessManager
        @#include "mynetworkaccessmanager.h"
        #include <QDebug>
        #include <QNetworkAccessManager>

        MyNetWorkAccessManager::MyNetWorkAccessManager()
        {
        }

        QNetworkReply* MyNetWorkAccessManager::deleteResource(const QNetworkRequest &request)
        {
        qDebug("1");
        return this->QNetworkAccessManager::deleteResource(request);
        }

        QNetworkReply* MyNetWorkAccessManager::get(const QNetworkRequest &request)
        {
        qDebug("2");
        return this->QNetworkAccessManager::get(request);
        }

        QNetworkReply* MyNetWorkAccessManager::head(const QNetworkRequest &request)
        {
        qDebug("3");
        return this->QNetworkAccessManager::head(request);
        }

        QNetworkReply* MyNetWorkAccessManager::post(const QNetworkRequest &request, QIODevice *data)
        {
        qDebug("4");
        return this->QNetworkAccessManager::post(request,data);
        }

        QNetworkReply* MyNetWorkAccessManager::post(const QNetworkRequest &request, const QByteArray &data)
        {
        qDebug("5");
        return this->QNetworkAccessManager::post(request,data);
        }

        QNetworkReply* MyNetWorkAccessManager::post(const QNetworkRequest &request, QHttpMultiPart *multiPart)
        {
        qDebug("6");
        return this->QNetworkAccessManager::post(request,multiPart);
        }

        QNetworkReply* MyNetWorkAccessManager::put(const QNetworkRequest &request, const QByteArray &data)
        {
        qDebug("7");
        return this->QNetworkAccessManager::put(request,data);
        }

        QNetworkReply* MyNetWorkAccessManager::put(const QNetworkRequest &request, QIODevice *data)
        {
        qDebug("8");
        return this->QNetworkAccessManager::put(request,data);
        }

        QNetworkReply* MyNetWorkAccessManager::put(const QNetworkRequest &request, QHttpMultiPart *multiPart)
        {
        qDebug("9");
        return this->QNetworkAccessManager::put(request,multiPart);
        }

        QNetworkReply* MyNetWorkAccessManager::sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data)
        {
        qDebug("10");
        return this->QNetworkAccessManager::sendCustomRequest(request,verb,data);
        }
        @

        When I use @// netWorkAccessManager->get(*request);@
        The console print "2".
        But When I use @ui->webView->load(*request);@
        The console did not print anything.Why?
        And how could I get all Http request which send by my application?
        Thank you again.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Don't do

          @load(*request);@

          It's a memory leak.

          You are setting your netWorkAccessManager on a QWebPage that has nothing to do with your QWebView, so your QWebView uses it's QNetworkAccessManager.

          Also remove all these this-> statement, you are calling the base class implementation not an element of your class.

          Hope it will get you further

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • B Offline
            B Offline
            BlueRhino
            wrote on last edited by
            #5

            [quote author="SGaist" date="1375870771"]Don't do

            @load(*request);@

            It's a memory leak.

            You are setting your netWorkAccessManager on a QWebPage that has nothing to do with your QWebView, so your QWebView uses it's QNetworkAccessManager.

            Also remove all these this-> statement, you are calling the base class implementation not an element of your class.

            Hope it will get you further[/quote]
            Thanks for your answer.It really get me further:)
            This is my test code.I just want to test whether the QWebView call MyNetWorkAccessManager`s method.
            OK.Let me describe what I want to do.
            At frist I wrote a very simple browser by using QWebView.
            Then I use the browser to surf the Internet.And I will get and store all the HTTP request which send by my browser.
            At last I can resend one of these HTTP request and make sure which DOM element will change after the HTTP response return.

            So,How could I get all the HTTP request which send by my browser?

            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