Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get the html's source from a https url with QNetworkAccessManager
Forum Updated to NodeBB v4.3 + New Features

Get the html's source from a https url with QNetworkAccessManager

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 2.1k Views 1 Watching
  • 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
    An other french
    wrote on last edited by An other french
    #1

    Hello,
    Now, all web's cite is secured with https protocol.
    For a personal automatic's search on the web, i need to get some areas under a html code.
    So, with no secured connection, no problemo.
    But, the best answers aren't in these ones.

    A short code to explain is better than my poor english.

    #include <QWidget>
    #include <QNetworkAccessManager>
    #include <QNetworkReply>
    
        QNetworkAccessManager *manager;
     
    manager = new QNetworkAccessManager(this);
     
        QNetworkRequest request; 
    request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
    request.setUrl(QUrl("https://forum.qt.io/topic/95745/get-the-html-s-source-from-a-https-url-with-qnetworkaccessmanager"));
    request.setRawHeader("User-Agent", "MyOwnBrowser 1.0");
     
        QNetworkReply *response;
     
    response = manager->get(request);
    connect(response, &QNetworkReply::finished,this,&Form::getResult );
     
    void form2::getResult() {
    qDebug() << "https://forum.qt.io/category/10/general-and-desktop";
    qDebug() << "html "<< response->readAll();
    ui->label_2->setText("one think done");
    }
    

    In some discussions, i can read about SSL's configuration and it said to add it under the compiler command's line. I put mine.

    qmake.exe "xyz.pro" -spec win32-g++ "CONFIG+=debug" "CONFIG+=qml_debug" && E:/Qt/Tools/mingw530_32/bin/mingw32-make.exe qmake_all
    

    No idea how to install the Ssl configuration in the mingw32 compiler if it needed.

    I earded about redirection which it not applied in this code.

    Some helps Please.
    Thanks for reading.

    Ps: surpise works with https://forum.qt.io
    So try with request.setUrl(QUrl("https://www.google.fr/search?q=qt+ssl+configuration"));

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      You don't have do anything for HTTPS. You should just use the HTTPS url and it should work fine.

      What is your real issue ? What is not working ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      3
      • A Offline
        A Offline
        An other french
        wrote on last edited by An other french
        #3

        see my Debug window

        Starting xxxx.exe...
        libpng warning: iCCP: known incorrect sRGB profile
        url  QUrl("https://www.google.fr/search?q=qt+ssl+configuration&oq=Ssl+Configuration+qt")
        html  ""             //   from  response->readAll();
        redirect  QUrl("")   //   from qDebug() << "redirect "<< response->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
        one think done
        
        1 Reply Last reply
        0
        • M Offline
          M Offline
          mpergand
          wrote on last edited by mpergand
          #4

          @An-other-french said in Get the html's source from a https url with QNetworkAccessManager:

          QNetworkReply *response;

          response = manager->get(request);

          try:
          reponse->ignoreSslErrors();

          1 Reply Last reply
          0
          • A Offline
            A Offline
            An other french
            wrote on last edited by An other french
            #5

            No way to show the html code from a google search
            insert libeay32.dll and ssleay32.dll in the folder "Qt\5.9.4\mingw53_32\bin"

            1 Reply Last reply
            1
            • A Offline
              A Offline
              An other french
              wrote on last edited by An other french
              #6

              http://doc.qt.io/qt-5/qnetworkreply.html#ignoreSslErrors-1

              void Form::on_pushButton_4_clicked()
              {
              manager = new QNetworkAccessManager(this);
              QNetworkRequest request;
              request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
              QList<QSslCertificate> cert = QSslCertificate::fromPath(QLatin1String("server-certificate.pem"));
              QSslError error(QSslError::SelfSignedCertificate, cert.at(0));
              QList<QSslError> expectedSslErrors;
              expectedSslErrors.append(error);
              request.setUrl(QUrl("https://www.google.fr/search?q=qt+ssl+configuration&oq=Ssl+Configuration+qt"));
              response = manager->get(request);
              connect(response, &QNetworkReply::finished,this,&Form::getResult2 );
              response->ignoreSslErrors(expectedSslErrors);
              }
              

              an error :

              ASSERT failure in QList<T>::at: "index out of range", file E:\Qt\5.9.4\mingw53_32\include/QtCore/qlist.h, line 541
              C:/.../Test QT Projet/build-test2-Desktop_Qt_5_9_4_MinGW_32bit-Debug/debug/test2.exe exited with code 3
              
              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @An-other-french said in Get the html's source from a https url with QNetworkAccessManager:

                QList<QSslCertificate> cert = QSslCertificate::fromPath(QLatin1String("server-certificate.pem"));

                You should check if there is an entry before accessing it...

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                2

                • Login

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