Cannot retrieve page contents through HTTPS with Q

2019-09-17 08:17发布

I am trying to connect to a HTTPS website (for example, Netflix), but cannot retrieve content of the page. I got OpenSSL lib in my folder and .pro, but I don't know what's wrong. Thanks for your time.

Screenshot of the error:

CONSOLE OUTPUT

Screenshot of the .pro:

CONSOLE OUTPUT

As you can see, the console is empty.

The code:

void get_page(){

    QEventLoop eventLoop;

    QNetworkAccessManager mgr;
    QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));

    QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration();
    sslConfig.setProtocol( QSsl::SslV3 );
    QSslConfiguration::setDefaultConfiguration(sslConfig);


    QNetworkRequest req(QUrl(QString("https://www.netflix.com/globallogin")));
    req.setHeader(QNetworkRequest::UserAgentHeader, "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.101 Safari/537.36 OPR/25.0.1614.50");
    req.setRawHeader("Host", "www.netflix.com");
    QNetworkReply *reply = mgr.get(req);
    eventLoop.exec();

    QString data = reply->readAll();

    if (reply->error() == QNetworkReply::NoError) {
        qDebug(data.toUtf8().constData());
    } else {
        qDebug() << "Failure" <<reply->errorString();
        delete reply;
    }
}

0条回答
登录 后发表回答