遵循QT5.5中的重定向



我有一个从Qt 5.6 运行良好的程序

const QUrl qurl(url);
QNetworkRequest request(qurl);
//github redirects the request, so this attribute must be set to true, otherwise returns nothing
//from qt5.6
request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
QNetworkAccessManager manager;
QNetworkReply * reply = manager.get(request);

不幸的是,这只适用于Qt 5.6

有人能帮我重定向到Qt5.5(Ubuntu 16.04(吗?我想我必须手动遵循重定向,但我没有找到关于它的教程。

我找到了Qt4->QNetworkReply和301重定向的解决方案

我希望Qt5有更多的"更新"。

感谢

这是我按照Qt4风格解决问题的方法,如QNetworkReply和301重定向。

如果有人有更好的解决方案,请张贴

QNetworkAccessManager manager;
QVariant possibleRedirectUrl;
QNetworkReply * reply;
QUrl qurl;
qurl.setUrl(url);
//we check if there is any redirect to follow it
//from Qt 5.6 redirects can be automatically followed by setting
//request.setAttribute(QNetworkRequest::FollowRedirectsAttribute, true);
//here is done automatically becaus of Ubuntu 16.04 Qt version (5.5)
do{
qInfo() <<"Downloading " << qurl;
QNetworkRequest request(qurl);
reply = manager.get(request);
qInfo() << "waiting to finish...";
_timeout=false;
_timer->start(timeout);
//if download takes more time that set on timeout cancel download
while(!_timeout){
qApp->processEvents();
if(reply->isFinished()) break;
}
_timeout = false;
qInfo() << "finished!";
possibleRedirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
qurl = possibleRedirectUrl.toUrl();
qInfo() << qurl;
}while(possibleRedirectUrl.isValid());

相关内容

  • 没有找到相关文章

最新更新