使用SSL的QT下载视频不起作用

时间:2017-02-19 07:21:53

标签: qt ssl video download

此代码下载视频,但由于某种原因无效

globals.h

QString videoDirectLink = "";

mainwindow.cpp

#include "globals.h"



void MainWindow::readOutput() {

        QByteArray outData = myProcess->readAllStandardOutput();  // read from CMD
        videoDirectLink = outData; //  videoDirectLink Contains https://media08.vbox7.com/s/91/91f4c651car96dafe736.mp4

        if (videoDirectLink.contains("https")) {
            // SSL downloading
            QNetworkAccessManager *manager2 = new QNetworkAccessManager(this);
            connect(manager2, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)));
            QNetworkRequest *req = new QNetworkRequest();
            req->setUrl(QUrl(videoDirectLink));  //videoDirectLink
            QSslConfiguration configSsl = QSslConfiguration::defaultConfiguration();
            configSsl.setProtocol(QSsl::AnyProtocol);
            req->setSslConfiguration(configSsl);

            connect(manager2->get(*req), SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64))); 
    }

如果更改req->setUrl(QUrl(videoDirectLink));
req->setUrl(QUrl("https://media08.vbox7.com/s/91/91f4c651car96dafe736.mp4"));

QString n ="https://media08.vbox7.com/s/91/91f4c651car96dafe736.mp4";
req->setUrl(QUrl(n));  

一切正常

这是无需SSL即可下载的代码。原理是一样的

globals.h

QString videoDirectLink = "";

mainwindow.cpp

#include "globals.h"
QNetworkAccessManager *manager = new QNetworkAccessManager(this);

    // start downloading
    connect(manager, SIGNAL(finished(QNetworkReply*)),
            this, SLOT(downloadFinished(QNetworkReply*)));

    QString target = videoDirectLink;
    QUrl url = QUrl::fromEncoded(target.toLocal8Bit());
    connect(manager->get(QNetworkRequest(url)), SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64)));

我尝试添加编码,但这不是问题。 其他建议?

//不工作

 void MainWindow::readOutput() {

        QString outData = myProcess->readAllStandardOutput();  // URL -> https://www.vbox7.com/play:91f4c651ca
        videoDirectLink = outData; //  videoDirectLink -> https://media28.vbox7.com/s/91/91f4c651car96dafe736.mp4

        if (videoDirectLink.contains("https")) {


            QNetworkAccessManager *manager2 = new QNetworkAccessManager(this);
            connect(manager2, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)));
            QNetworkRequest *req = new QNetworkRequest();
            req->setUrl(QUrl(videoDirectLink));  //videoDirectLink
            connect(manager2->get(*req), SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64,qint64)));
            QMessageBox::information(this,"SSL downloading",videoDirectLink,"ok"); // displays https://media28.vbox7.com/s/91/91f4c651car96dafe736.mp4

        }
    }

0 个答案:

没有答案