lundi 20 avril 2015

Downloading file over HTTPS using Qt behind authenticating proxy

I am trying to download a file, publicly available over an HTTPS URL, using Qt 4.8. I am behind a corporate authenticating proxy (over which I have no control).

I am using QNetworkAccessManager, as shown below:

bool FileDownloader::download(const QString& fileUrl, const QString& fileName)
    QString outputFileName = fileName.isEmpty() ? fileNameFromUrl(fileUrl) : fileName;


    QUrl url(fileUrl);

    QNetworkReply* pReply = _networkAccessManager.get(QNetworkRequest(url));

    connect(pReply, SIGNAL(finished()), _pEventLoop, SLOT(quit()));
    connect(pReply, SIGNAL(readyRead()), this, SLOT(onReadyRead()));
    connect(pReply, SIGNAL(sslErrors(const QList<QSslError>&)), this, SLOT(onSslErrors(const QList<QSslError>&)));
    connect(pReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(onError(QNetworkReply::NetworkError)));


    return true;

As soon as I call QNetworkAccessManager::get(), and receive a QNetworkReply object, I connect to its sslErrors signal as mentioned in the docs. Following the same docs, I'm also calling ignoreSslErrors() in the slot connected to that signal:

void FileDownloader::onSslErrors(const QList<QSslError>& sslErrors)
    QNetworkReply* pReply = (QNetworkReply*)(sender());

However, I never receive an sslErrors signal, I always get an error signal, which I'm handling in the onError slot, and which always says:

SSL handshake failed

I'm calling the download functionality thus:

FileDownloader fileDownloader;

I do not want to use other libraries like libcurl because I don't want to introduce dependencies.

So how can I download the file over HTTPS using Qt?

Aucun commentaire:

Enregistrer un commentaire