Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

HTTPS with QNetworkAccessManager not working



  • This is a thread that I am trying to get https working in and I can't.. Help please!

    MyHttpsThread::MyHttpsThread(QObject *parent) :
    QThread(parent)
    {
    }

    MyHttpsThread::~MyHttpsThread()
    {
    m_mutex.lock();
    m_quit = true;
    m_mutex.unlock();
    wait();
    }

    void MyHttpsThread::startMyHttpsThread(void)
    {

    const QMutexLocker locker(&m_mutex);
    //m_serror = error;
    
    
    if (!isRunning())
        start();
    

    }

    void MyHttpsThread::run()
    {
    qDebug() << "MyHttpsThread started";

    QNetworkRequest netRequest;
    QSslConfiguration sSlConfig;
    
    netManager = new QNetworkAccessManager();
    
    sSlConfig.setDefaultConfiguration(QSslConfiguration::defaultConfiguration());
    sSlConfig.setProtocol(QSsl::TlsV1_2);
    netRequest.setSslConfiguration(sSlConfig);
    netRequest.setUrl(QUrl("https://tlsinfo.nails.eu.org"));
    
    connect(netManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
    //connect(netManager, SIGNAL(error(QNetworkReply*, QNetworkReply::NetworkError&)), this, SLOT(errorReturned(QNetworkReply*, QNetworkReply::NetworkError&)));
    connect(netManager, SIGNAL(sslErrors(QNetworkReply*, const QList<QSslError>&)), this, SLOT(onSslErrors(QNetworkReply*, const QList<QSslError>&)));
    netManager->get(netRequest);
    
    while (!m_quit) {
        QThread::msleep(1);
    }   // while (!m_quit)
    

    }

    void MyHttpsThread::replyFinished(QNetworkReply* reply)
    {
    int ii;
    QByteArray data = reply->readAll();
    ii = 0;
    }

    void MyHttpsThread::errorReturned(QNetworkReply*, QNetworkReply::NetworkError &err)
    {
    int ii;
    ii = 0;
    }

    void MyHttpsThread::onSslErrors(QNetworkReply* reply, const QList<QSslError> &errors)
    {
    int ii;
    ii = 0;
    }


  • Moderators

    @Dave-P. said in HTTPS with QNetworkAccessManager not working:

    I am trying to get https working in and I can't..

    Please provide more details: What doesn't work? What error messages do you get?

    Anyway, Qt requires OpenSSL to use HTTPS. Have you installed OpenSSL 1.0.2 and put it in a PATH that your app can find?



  • @JKSH Hi,

    I did install the latest openssl but because of homebrew issues it had to be installed at: /Users/davidpatton1/scratch/openssl

    Here is the openssl version -a output...
    OpenSSL 1.1.1-pre9-dev xx XXX xxxx
    built on: Tue Jul 17 03:10:57 2018 UTC
    platform: darwin64-x86_64-cc
    options: bn(64,64) rc4(16x,int) des(int) idea(int) blowfish(ptr)
    compiler: cc -fPIC -arch x86_64 -Wa,--noexecstack -Qunused-arguments -O3 -Wall -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_CPUID_OBJ -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM -DRC4_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DX25519_ASM -DPADLOCK_ASM -DPOLY1305_ASM -D_REENTRANT -DNDEBUG -I/usr/local/opt/openssl/include
    OPENSSLDIR: "/usr/local/ssl"
    ENGINESDIR: "/usr/local/lib/engines-1.1"
    Seeding source: os-specific

    By not working I mean that neither the: void MyHttpsThread::replyFinished(QNetworkReply* reply) nor the void MyHttpsThread::onSslErrors(QNetworkReply* reply, const QList<QSslError> &errors)

    routines are ever hit. Opening https://tlsinfo.nails.eu.org in my browser works fine..

    Thanks..


  • Moderators

    @Dave-P. said in HTTPS with QNetworkAccessManager not working:

    OpenSSL 1.1.1-pre9-dev xx XXX xxxx

    OpenSSL v1.1 is incompatible with OpenSSL v1.0.2.

    For now, try installing v1.0.2 to check if it works.

    After that, if you want to use v1.1, I think you need to rebuild Qt to link against OpenSSL v1.1


Log in to reply