|
42 | 42 | #include "qgscategorizedsymbolrenderer.h"
|
43 | 43 | #include "qgsvectorlayerlabeling.h"
|
44 | 44 |
|
45 |
| -#include <QEventLoop> |
46 | 45 | #include <QNetworkRequest>
|
47 |
| -#include <QNetworkReply> |
48 |
| -#include <QThread> |
| 46 | +#include "qgsblockingnetworkrequest.h" |
49 | 47 | #include <QJsonDocument>
|
50 | 48 | #include <QJsonObject>
|
51 | 49 |
|
@@ -471,57 +469,27 @@ QList<quint32> QgsArcGisRestUtils::getObjectIdsByExtent( const QString &layerurl
|
471 | 469 |
|
472 | 470 | QByteArray QgsArcGisRestUtils::queryService( const QUrl &u, const QString &authcfg, QString &errorTitle, QString &errorText, QgsFeedback *feedback )
|
473 | 471 | {
|
474 |
| - QEventLoop loop; |
475 | 472 | QUrl url = parseUrl( u );
|
476 | 473 |
|
477 | 474 | QNetworkRequest request( url );
|
| 475 | + QgsBlockingNetworkRequest networkRequest; |
| 476 | + networkRequest.setAuthCfg( authcfg ); |
| 477 | + const QgsBlockingNetworkRequest::ErrorCode error = networkRequest.get( request, false, feedback ); |
478 | 478 |
|
479 |
| - if ( !authcfg.isEmpty() ) |
480 |
| - { |
481 |
| - QgsApplication::authManager()->updateNetworkRequest( request, authcfg ); |
482 |
| - } |
483 |
| - |
484 |
| - QNetworkReply *reply = nullptr; |
485 |
| - QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance(); |
| 479 | + if ( feedback && feedback->isCanceled() ) |
| 480 | + return QByteArray(); |
486 | 481 |
|
487 |
| - // Request data, handling redirects |
488 |
| - while ( true ) |
| 482 | + // Handle network errors |
| 483 | + if ( error != QgsBlockingNetworkRequest::NoError ) |
489 | 484 | {
|
490 |
| - reply = nam->get( request ); |
491 |
| - QObject::connect( reply, &QNetworkReply::finished, &loop, &QEventLoop::quit ); |
492 |
| - if ( feedback ) |
493 |
| - { |
494 |
| - QObject::connect( feedback, &QgsFeedback::canceled, reply, &QNetworkReply::abort ); |
495 |
| - } |
496 |
| - |
497 |
| - loop.exec( QEventLoop::ExcludeUserInputEvents ); |
498 |
| - |
499 |
| - reply->deleteLater(); |
500 |
| - |
501 |
| - if ( feedback && feedback->isCanceled() ) |
502 |
| - return QByteArray(); |
503 |
| - |
504 |
| - // Handle network errors |
505 |
| - if ( reply->error() != QNetworkReply::NoError ) |
506 |
| - { |
507 |
| - QgsDebugMsg( QStringLiteral( "Network error: %1" ).arg( reply->errorString() ) ); |
508 |
| - errorTitle = QStringLiteral( "Network error" ); |
509 |
| - errorText = reply->errorString(); |
510 |
| - return QByteArray(); |
511 |
| - } |
512 |
| - |
513 |
| - // Handle HTTP redirects |
514 |
| - QVariant redirect = reply->attribute( QNetworkRequest::RedirectionTargetAttribute ); |
515 |
| - if ( redirect.isNull() ) |
516 |
| - { |
517 |
| - break; |
518 |
| - } |
519 |
| - |
520 |
| - QgsDebugMsg( "redirecting to " + redirect.toUrl().toString() ); |
521 |
| - request.setUrl( redirect.toUrl() ); |
| 485 | + QgsDebugMsg( QStringLiteral( "Network error: %1" ).arg( networkRequest.errorMessage() ) ); |
| 486 | + errorTitle = QStringLiteral( "Network error" ); |
| 487 | + errorText = networkRequest.errorMessage(); |
| 488 | + return QByteArray(); |
522 | 489 | }
|
523 |
| - QByteArray result = reply->readAll(); |
524 |
| - return result; |
| 490 | + |
| 491 | + const QgsNetworkReplyContent content = networkRequest.reply(); |
| 492 | + return content.content(); |
525 | 493 | }
|
526 | 494 |
|
527 | 495 | QVariantMap QgsArcGisRestUtils::queryServiceJSON( const QUrl &url, const QString &authcfg, QString &errorTitle, QString &errorText, QgsFeedback *feedback )
|
|
0 commit comments