Cannot retrieve page contents through HTTPS with QNetworkAccessManager

﹥>﹥吖頭↗ 提交于 2019-12-11 16:14:50

问题


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:

Screenshot of the .pro:

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;
    }
}

来源:https://stackoverflow.com/questions/26565666/cannot-retrieve-page-contents-through-https-with-qnetworkaccessmanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!