问题
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