mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
Downloader: enable auto following re-directed request
This commit is contained in:
parent
574aa4e70a
commit
751082c820
@ -11,19 +11,37 @@ VDownloader::VDownloader(QObject *parent)
|
||||
|
||||
void VDownloader::handleDownloadFinished(QNetworkReply *reply)
|
||||
{
|
||||
if (reply->error() != QNetworkReply::NoError) {
|
||||
qWarning() << "download reply error" << reply->error();
|
||||
}
|
||||
|
||||
data = reply->readAll();
|
||||
reply->deleteLater();
|
||||
emit downloadFinished(data, reply->url().toString());
|
||||
}
|
||||
|
||||
static QNetworkRequest networkRequest(const QUrl &p_url)
|
||||
{
|
||||
QNetworkRequest request(p_url);
|
||||
/*
|
||||
QSslConfiguration config = QSslConfiguration::defaultConfiguration();
|
||||
config.setProtocol(QSsl::SslV3);
|
||||
config.setPeerVerifyMode(QSslSocket::VerifyNone);
|
||||
request.setSslConfiguration(config);
|
||||
*/
|
||||
|
||||
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
void VDownloader::download(const QUrl &p_url)
|
||||
{
|
||||
if (!p_url.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QNetworkRequest request(p_url);
|
||||
webCtrl.get(request);
|
||||
webCtrl.get(networkRequest(p_url));
|
||||
}
|
||||
|
||||
QByteArray VDownloader::downloadSync(const QUrl &p_url)
|
||||
@ -37,12 +55,16 @@ QByteArray VDownloader::downloadSync(const QUrl &p_url)
|
||||
QNetworkAccessManager nam;
|
||||
connect(&nam, &QNetworkAccessManager::finished,
|
||||
[&data, &finished](QNetworkReply *p_reply) {
|
||||
if (p_reply->error() != QNetworkReply::NoError) {
|
||||
qWarning() << "download reply error" << p_reply->error();
|
||||
}
|
||||
|
||||
data = p_reply->readAll();
|
||||
p_reply->deleteLater();
|
||||
finished = true;
|
||||
});
|
||||
|
||||
nam.get(QNetworkRequest(p_url));
|
||||
nam.get(networkRequest(p_url));
|
||||
|
||||
while (!finished) {
|
||||
VUtils::sleepWait(100);
|
||||
|
Loading…
x
Reference in New Issue
Block a user