我正在尝试连接到HTTPS网站(例如,Netflix),但无法检索该网页的内容。我在我的文件夹和.pro中获得了OpenSSL lib,但我不知道出了什么问题。谢谢你的时间。
错误的屏幕截图:
.pro:
的屏幕截图
如您所见,控制台是空的。
代码:
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;
}
}