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. QNetworkRequest for https
Forum Updated to NodeBB v4.3 + New Features

QNetworkRequest for https

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.4k Views 2 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.
  • I Offline
    I Offline
    Infinity
    wrote on last edited by
    #1

    I want to read json data from a remote server with an https get request. The server requires an Authorizsation header. I tried the following:

    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
        connect(manager, &QNetworkAccessManager::finished, this, &AccountsTableModel::replyFinished);
    QNetworkRequest request =  QNetworkRequest(QUrl("https://x.x.x.x:y/xyz"));
    request.setSslConfiguration(QSslConfiguration::defaultConfiguration());
    request.setRawHeader(QByteArray("Authorization"), QByteArray("bearer xyz"));
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
    
    QNetworkReply *reply = manager->get(request);
    
    connect(reply, QOverload<QNetworkReply::NetworkError>::of(&QNetworkReply::error), this, &AccountsTableModel::replyError);
    connect(reply, &QNetworkReply::sslErrors, this, &AccountsTableModel::replySslError);
    
    void AccountsTableModel::replyError(QNetworkReply::NetworkError code)
    {
        qDebug() << "Error";
        qDebug() << (int) code;
    }
    
    void AccountsTableModel::replySslError(const QList<QSslError> &sslErrors)
    {
        for (int i = 0; i < sslErrors.size(); i++) {
            qDebug() << "Error " << i << sslErrors.at(i).errorString();
        }
    }
    

    When I run the code I get the following error messages:

    6
    "SSL handshake failed"
    "OpenSSL 1.0.2k-fips 26 Jan 2017"
    ""

    I'm using: Qt 5.12.3 on a linux system with openssl 1.0.2

    What is the correct way to use QNetwokrRequest with ssl?

    Did I set the Authorization header correctly?

    Where and how can I define the certificate?

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

      Hi,

      How did you install Qt ?
      Since you're on a linux distribution, and before hunting down what's going on with Qt 5.12.3, you can check that your code is working correctly using your distribution provided Qt.

      On a side note you can use:

      qDebug() << QSslSocket::sslLibraryBuildVersionString();
      qDebug() << QSslSocket::sslLibraryVersionString();
      

      To see the version used to build Qt and the one currently loaded.

      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
      1

      • Login

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