Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. download url with redirection
Forum Updated to NodeBB v4.3 + New Features

download url with redirection

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 5 Posters 907 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S skylendar

    I'm using qt5.15

    Pl45m4P Offline
    Pl45m4P Offline
    Pl45m4
    wrote on last edited by
    #4

    @skylendar

    The default value in 5.15 is:

    ManualRedirectPolicy: not following any redirects.

    • https://doc.qt.io/qt-5/qnetworkrequest.html#RedirectPolicy-enum

    Try QNetworkRequest::SameOriginRedirectPolicy


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    1 Reply Last reply
    1
    • S Offline
      S Offline
      skylendar
      wrote on last edited by
      #5

      will try, thx for the answer

      1 Reply Last reply
      0
      • S Offline
        S Offline
        skylendar
        wrote on last edited by
        #6

        @Pl45m4 said in download url with redirection:

        QNetworkRequest::SameOriginRedirectPolicy

        Ok, I saw this enum, but it is unclear where to use it, because the QNetworkRequest header doesn't seem to provide any method using it.

        Pl45m4P 1 Reply Last reply
        0
        • S Offline
          S Offline
          skylendar
          wrote on last edited by
          #7

          Oops, it is used by the networkaccessmanager, but by individual requests

          Sorry...

          1 Reply Last reply
          0
          • S Offline
            S Offline
            skylendar
            wrote on last edited by
            #8

            Ok, it's late, will try tomorrow

            1 Reply Last reply
            0
            • S skylendar

              @Pl45m4 said in download url with redirection:

              QNetworkRequest::SameOriginRedirectPolicy

              Ok, I saw this enum, but it is unclear where to use it, because the QNetworkRequest header doesn't seem to provide any method using it.

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by Pl45m4
              #9

              @skylendar

              Not tested:

                  QNetworkAccessManager nam;
                  nam.setRedirectPolicy(QNetworkRequest::SameOriginRedirectPolicy); // set on NAM for all further requests
                  // or:
                  QNetworkRequest req; // this request only
                  req.setAttribute(QNetworkRequest::Attribute::RedirectPolicyAttribute,
                                   QNetworkRequest::SameOriginRedirectPolicy);
              

              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              0
              • S Offline
                S Offline
                skylendar
                wrote on last edited by
                #10

                I tested it, reply->error() returns NoError, but I only got an empty file...

                jsulmJ 1 Reply Last reply
                0
                • S skylendar

                  I tested it, reply->error() returns NoError, but I only got an empty file...

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #11

                  @skylendar Please show your current code.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    skylendar
                    wrote on last edited by
                    #12
                    #include <QtCore/QtCore>
                    #include <QtNetwork/QtNetwork>
                    
                    int main(int argc, char *argv[])
                    {
                        QCoreApplication app(argc, argv);
                    
                        QNetworkAccessManager manager;
                    		manager.setRedirectPolicy(QNetworkRequest::SameOriginRedirectPolicy);
                    		
                        QUrl initialUrl("https://www.dropbox.com/scl/fo/y3naz62gy6f6qfrhquu7u/h/all_ast/ast_100_199/ast100/s100001s.se1?rlkey=ejltdhb262zglm7eo6yfj2940&dl=0");
                    
                    
                        QNetworkRequest request;
                       request.setUrl(initialUrl);
                    		request.setAttribute(QNetworkRequest::Attribute::RedirectPolicyAttribute,
                                         QNetworkRequest::SameOriginRedirectPolicy);
                    
                    		QNetworkReply *reply = manager.get(request);
                    		while (!reply->isFinished())        qApp->processEvents(QEventLoop::WaitForMoreEvents, 500);
                    
                    		qDebug() << "erroe:" << reply->error() << "reply size:" <<    reply->size();
                    		QFile f("se00020s.se1");
                    		f.open(QIODevice::WriteOnly);
                    		f.write(reply->readAll());
                    		f.close();
                                    reply->deleteLater();
                    		
                    }
                    

                    This code is compiled with the usual:

                    g++ -I /usr/include/qt5 redir1.cpp -lQt5Core -lQt5Network
                    

                    Before, the code returned an empty file. Now, it contains an html page asking for a dropbox identification, not the wanted file.

                    Pl45m4P 1 Reply Last reply
                    0
                    • S skylendar
                      #include <QtCore/QtCore>
                      #include <QtNetwork/QtNetwork>
                      
                      int main(int argc, char *argv[])
                      {
                          QCoreApplication app(argc, argv);
                      
                          QNetworkAccessManager manager;
                      		manager.setRedirectPolicy(QNetworkRequest::SameOriginRedirectPolicy);
                      		
                          QUrl initialUrl("https://www.dropbox.com/scl/fo/y3naz62gy6f6qfrhquu7u/h/all_ast/ast_100_199/ast100/s100001s.se1?rlkey=ejltdhb262zglm7eo6yfj2940&dl=0");
                      
                      
                          QNetworkRequest request;
                         request.setUrl(initialUrl);
                      		request.setAttribute(QNetworkRequest::Attribute::RedirectPolicyAttribute,
                                           QNetworkRequest::SameOriginRedirectPolicy);
                      
                      		QNetworkReply *reply = manager.get(request);
                      		while (!reply->isFinished())        qApp->processEvents(QEventLoop::WaitForMoreEvents, 500);
                      
                      		qDebug() << "erroe:" << reply->error() << "reply size:" <<    reply->size();
                      		QFile f("se00020s.se1");
                      		f.open(QIODevice::WriteOnly);
                      		f.write(reply->readAll());
                      		f.close();
                                      reply->deleteLater();
                      		
                      }
                      

                      This code is compiled with the usual:

                      g++ -I /usr/include/qt5 redir1.cpp -lQt5Core -lQt5Network
                      

                      Before, the code returned an empty file. Now, it contains an html page asking for a dropbox identification, not the wanted file.

                      Pl45m4P Offline
                      Pl45m4P Offline
                      Pl45m4
                      wrote on last edited by
                      #13

                      @skylendar

                      If your file is not public, you need to add your credentials to authenticate


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      1 Reply Last reply
                      1
                      • S Offline
                        S Offline
                        skylendar
                        wrote on last edited by
                        #14

                        but the file is public. Anyone can download it !

                        Christian EhrlicherC JonBJ Pl45m4P 3 Replies Last reply
                        1
                        • S skylendar

                          but the file is public. Anyone can download it !

                          Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #15

                          @skylendar said in download url with redirection:

                          but the file is public. Anyone can download it !

                          I need to enter some kind of credentials...

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          1 Reply Last reply
                          1
                          • S skylendar

                            but the file is public. Anyone can download it !

                            JonBJ Offline
                            JonBJ Offline
                            JonB
                            wrote on last edited by
                            #16

                            @skylendar Did you at least try visiting the Url from an Incognito window?

                            1 Reply Last reply
                            0
                            • S skylendar

                              but the file is public. Anyone can download it !

                              Pl45m4P Offline
                              Pl45m4P Offline
                              Pl45m4
                              wrote on last edited by Pl45m4
                              #17

                              @skylendar said in download url with redirection:

                              but the file is public. Anyone can download it !

                              Maybe you are right, but it seems that DropBox changed its policies and it's required to authenticate somehow...

                              • https://www.dropboxforum.com/t5/Create-upload-and-share/New-URLs-for-shared-links-affecting-3rd-party-integrations/td-p/695197

                              This thread on DropBox forum says that it's not that easy anymore to share dropbox folders or files with anyone. :(
                              The link structure changed (type of file often not recognized anymore) and this authentication page was added

                              My favourite comment there:

                              One day someone got up there and decided to change the entire link structure in Dropbox. He didn't think that it might affect a lot of third-party apps, and in fact he didn't think about anything!

                              Which is very surprising for a serious company like Dropbox.

                              We already have a group of developers who are considering moving to Amazon's service.
                              In addition, they do not respond to support emails or opened tickets. Really disappointing, my whole app is just disabled.

                              Just disappointing and infuriating!

                              (source)

                              That seems about it! I know, security issue... etc. but I also know how DropBox was used to "quickly share a file" with a defined group or just with everyone who got that link.


                              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                              ~E. W. Dijkstra

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                skylendar
                                wrote on last edited by
                                #18

                                Ok folks, I thought I made a bug somewhere but this is a dropbox issue. Thx for your help

                                C.

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  skylendar
                                  wrote on last edited by
                                  #19

                                  I'm back again, because I was told that the provided url was wrong. with:

                                  https://www.dropbox.com/scl/fo/y3naz62gy6f6qfrhquu7u/h/all_ast/ast100/s100001s.se1?rlkey=ejltdhb262zglm7eo6yfj2940&dl=0
                                  

                                  I got the right file with curl but not with the qt test code, but this time, I got this:

                                  .se1 files are supported but something went wrong.

                                  and download is proposed via a sign up.

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    skylendar
                                    wrote on last edited by
                                    #20

                                    I also added :

                                    request.setRawHeader("User-Agent", "curl/7.54.1");
                                    

                                    but this time. my test utility returned:

                                    QNetworkReply::InsecureRedirectError
                                    
                                    1 Reply Last reply
                                    0

                                    • Login

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved