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 a file from URL have space

Download a file from URL have space

Scheduled Pinned Locked Moved Solved General and Desktop
18 Posts 3 Posters 3.3k Views 2 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.
  • A Offline
    A Offline
    ARASHz4
    wrote on last edited by
    #1

    Hi
    I can't download a file from URL have space or %20
    I test ' ' , '%20' , '+' but i can't download

    A 1 Reply Last reply
    0
    • A ARASHz4

      Hi
      I can't download a file from URL have space or %20
      I test ' ' , '%20' , '+' but i can't download

      A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      @ARASHz4 Show the code you are using to download the file.. specifically the part that makes the URL so we can see what's wrong.

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      A 1 Reply Last reply
      0
      • A ambershark

        @ARASHz4 Show the code you are using to download the file.. specifically the part that makes the URL so we can see what's wrong.

        A Offline
        A Offline
        ARASHz4
        wrote on last edited by ARASHz4
        #3

        @ambershark Hi
        this my code for download file

        DownloadManager = new QNetworkAccessManager(this);
        reply =  DownloadManager->get(QNetworkRequest(Url));
        

        Url is text a lineEdit

        A 1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          You should also show the code you are using to create the QUrl object.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          A 1 Reply Last reply
          0
          • SGaistS SGaist

            Hi,

            You should also show the code you are using to create the QUrl object.

            A Offline
            A Offline
            ARASHz4
            wrote on last edited by ARASHz4
            #5

            @SGaist
            this is my code
            and you can see my project

            1 Reply Last reply
            0
            • A ARASHz4

              @ambershark Hi
              this my code for download file

              DownloadManager = new QNetworkAccessManager(this);
              reply =  DownloadManager->get(QNetworkRequest(Url));
              

              Url is text a lineEdit

              A Offline
              A Offline
              ambershark
              wrote on last edited by
              #6

              @ARASHz4 Well if you look here http://doc.qt.io/qt-5/qurl.html#QUrl-2 you will see that QUrl will handle spaces for you. So that is weird that it isn't working because QNetworkRequest will turn your text QString into a QUrl automatically.

              So a thing you could do to test is make the QUrl yourself like so:

              QUrl myUrl(Url);
              Q_ASSERT(myUrl.isValid());
              reply = DownloadManager->get(QNetworkRequest(myUrl));
              

              If that shows it is valid, you could try making it more strict with:

              QUrl myUrl(Url, QUrl::StrictMode);
              Q_ASSERT(myUrl.isValid());
              

              That second one should fail if there is a problem.

              That should give you a better idea of if the url is valid or not.

              My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

              A 1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                I'd recommend taking a look at QUrl::fromUserInput which looks to be more appropriate in your use case.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                A 1 Reply Last reply
                1
                • A ambershark

                  @ARASHz4 Well if you look here http://doc.qt.io/qt-5/qurl.html#QUrl-2 you will see that QUrl will handle spaces for you. So that is weird that it isn't working because QNetworkRequest will turn your text QString into a QUrl automatically.

                  So a thing you could do to test is make the QUrl yourself like so:

                  QUrl myUrl(Url);
                  Q_ASSERT(myUrl.isValid());
                  reply = DownloadManager->get(QNetworkRequest(myUrl));
                  

                  If that shows it is valid, you could try making it more strict with:

                  QUrl myUrl(Url, QUrl::StrictMode);
                  Q_ASSERT(myUrl.isValid());
                  

                  That second one should fail if there is a problem.

                  That should give you a better idea of if the url is valid or not.

                  A Offline
                  A Offline
                  ARASHz4
                  wrote on last edited by
                  #8

                  @ambershark i use QUrl:
                  QUrl murl = mystr;
                  this code work?

                  1 Reply Last reply
                  0
                  • SGaistS SGaist

                    I'd recommend taking a look at QUrl::fromUserInput which looks to be more appropriate in your use case.

                    A Offline
                    A Offline
                    ARASHz4
                    wrote on last edited by ARASHz4
                    #9

                    @SGaist i test this but no difference
                    Error is : server replied: Not Acceptable

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Can you show what you are entering and what you URL is used to do your request ?

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      A 2 Replies Last reply
                      0
                      • SGaistS SGaist

                        Can you show what you are entering and what you URL is used to do your request ?

                        A Offline
                        A Offline
                        ARASHz4
                        wrote on last edited by
                        #11

                        @SGaist I test this pic :

                        http://www.mlhsartgallery.org/DS10sem1/V_Boswell/dawn%20pic%204.bmp
                        
                        A 1 Reply Last reply
                        0
                        • A ARASHz4

                          @SGaist I test this pic :

                          http://www.mlhsartgallery.org/DS10sem1/V_Boswell/dawn%20pic%204.bmp
                          
                          A Offline
                          A Offline
                          ambershark
                          wrote on last edited by
                          #12

                          @ARASHz4 Did you try setting the QUrl to strict mode and see if it is valid?

                          That url should work just fine, so there must be some problem in how you are setting your url.

                          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                          A 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            Can you show what you are entering and what you URL is used to do your request ?

                            A Offline
                            A Offline
                            ARASHz4
                            wrote on last edited by ARASHz4
                            #13

                            @SGaist I tried other urls with space or %20 work fine but way i can't download this pic

                            1 Reply Last reply
                            0
                            • A ambershark

                              @ARASHz4 Did you try setting the QUrl to strict mode and see if it is valid?

                              That url should work just fine, so there must be some problem in how you are setting your url.

                              A Offline
                              A Offline
                              ARASHz4
                              wrote on last edited by
                              #14

                              @ambershark yes is valid

                              Url = QUrl::fromUserInput(ui->addressLineEdit->text());
                              
                              qDebug()<<Url.isValid();
                              

                              return me true but i can't download this file!

                              A 1 Reply Last reply
                              0
                              • A ARASHz4

                                @ambershark yes is valid

                                Url = QUrl::fromUserInput(ui->addressLineEdit->text());
                                
                                qDebug()<<Url.isValid();
                                

                                return me true but i can't download this file!

                                A Offline
                                A Offline
                                ambershark
                                wrote on last edited by
                                #15

                                @ARASHz4 I'll write a quick test app and see if it works for me..

                                My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  The problem is not the URL. You are getting a 406 error.. Basically, the server tells you that your query is missing some stuff.

                                  QNetworkRequest request(url);
                                  request.setRawHeader("Accept", "*/*");
                                  request.setRawHeader("User-Agent", "name-of-your-application");
                                  

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  A 1 Reply Last reply
                                  1
                                  • SGaistS SGaist

                                    The problem is not the URL. You are getting a 406 error.. Basically, the server tells you that your query is missing some stuff.

                                    QNetworkRequest request(url);
                                    request.setRawHeader("Accept", "*/*");
                                    request.setRawHeader("User-Agent", "name-of-your-application");
                                    
                                    A Offline
                                    A Offline
                                    ARASHz4
                                    wrote on last edited by
                                    #17

                                    @SGaist thank you now i can download this file

                                    what doing this code?

                                    request.setRawHeader("Accept", "*/*");
                                    request.setRawHeader("User-Agent", "name-of-your-application");
                                    
                                    1 Reply Last reply
                                    0
                                    • SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      It's setting the HTTP Accept (definition 14.1) and User-Agent (definition 14.43) header. See RFC2616.

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      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