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. [Solved]Problem Downloading a file
Forum Updated to NodeBB v4.3 + New Features

[Solved]Problem Downloading a file

Scheduled Pinned Locked Moved General and Desktop
21 Posts 8 Posters 8.0k 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.
  • Q Offline
    Q Offline
    qwertyuiopearendil
    wrote on last edited by
    #1

    Hi All,
    Some of you know how should I create an url that contains "+" to be able to do a get using QNetworkAccessManager?
    When a try to perform a get to this link:
    http://myStore/zip/myZip+.zip
    I have an error: "ContentNotFoundError", but if I try to use it on Firefox it runs.
    The real name of my file is: myZip+.zip

    Thanks.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Robbin
      wrote on last edited by
      #2

      Have you tried "this":http://doc.qt.nokia.com/latest/qurl.html#toPercentEncoding ?

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qwertyuiopearendil
        wrote on last edited by
        #3

        Yes but it doesn't wirk

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          ZapB
          wrote on last edited by
          #4

          How are you constructing your url? Have you tried http://doc.qt.nokia.com/latest/qurl.html#fromEncoded-2 using QUrl::TolerantMode as the parsing mode?

          Nokia Certified Qt Specialist
          Interested in hearing about Qt related work

          1 Reply Last reply
          0
          • L Offline
            L Offline
            LinusA
            wrote on last edited by
            #5

            Well, the QUrl::toPercentEncoding() does exactly what you want, but without code and/or debug messages (how does your percent-encoded URL look?), we probably can't help you.

            Try your program with _%2_B instead of the + in the URL (without underscores, this forum doesn't let me post _%2_B without underscores, it allways turns to "+") and see if it works.

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              qwertyuiopearendil
              wrote on last edited by
              #6

              My url already have %_2_B instead of +, but server when i perform get answer: ContentNotFoundError, but if i put the same url into firefox I'm able to download right file.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Robbin
                wrote on last edited by
                #7

                as LinusA said - provide us with some code, else nobody can really help you further, without seeing what could be wrong. Also, post any qDebug() output you get from your app (most important the results from the http request of QNetworkAccessManager

                1 Reply Last reply
                0
                • Q Offline
                  Q Offline
                  qwertyuiopearendil
                  wrote on last edited by
                  #8

                  This is my code:

                  @
                  iNetReply = iNetManager->get(QNetworkRequest(QUrl("http://myStore-dev.myCompany.com/lmn/00000/fetch?device=00000&file=myFile+.zip")));
                  @

                  After this request function: connectionError, it's a slot connected in this way:

                  @
                  connect(iNetReply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(connectionError(QNetworkReply::NetworkError)));
                  @

                  Write on console: Error code= 203

                  @
                  void PlotterDownloadThread::connectionError(QNetworkReply::NetworkError code)
                  {
                  qDebug()<<"Error code= "<<code;
                  }
                  @

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Robbin
                    wrote on last edited by
                    #9

                    as stated earlier, your URL should be percent-encoded. I don't see the .toPercentEncoding() method used, even though you said you used it.

                    @
                    iNetReply = iNetManager->get(QNetworkRequest(QUrl("http://myStore-dev.myCompany.com/lmn/00000/fetch?device=00000&file=myFile+.zip")));
                    @

                    should be
                    @
                    iNetReply = iNetManager->get(QNetworkRequest(QUrl("http://myStore-dev.myCompany.com/lmn/00000/fetch?device=00000&file=myFile+.zip").toPercentEncoding()));
                    @

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      dangelog
                      wrote on last edited by
                      #10

                      [quote]My url already have %_2_B instead of +, but server when i perform get answer: ContentNotFoundError, but if i put the same url into firefox I’m able to download right file.[/quote]

                      Can you use wireshark or a similar tool to analyze the HTTP traffic and understand what's going on?

                      [quote author="Eus" date="1314173671"]as stated earlier, your URL should be percent-encoded. I don't see the .toPercentEncoding() method used, even though you said you used it.

                      @
                      iNetReply = iNetManager->get(QNetworkRequest(QUrl("http://myStore-dev.myCompany.com/lmn/00000/fetch?device=00000&file=myFile+.zip")));
                      @

                      should be
                      @
                      iNetReply = iNetManager->get(QNetworkRequest(QUrl("http://myStore-dev.myCompany.com/lmn/00000/fetch?device=00000&file=myFile+.zip").toPercentEncoding()));@
                      [/quote]

                      This is completely nonsense. Not only that doesn't compile, but there's no QNetworkRequest(QByteArray) ctor, and you don't want to percent encode that url (thus escaping :, /, ?, &, etc.).

                      Software Engineer
                      KDAB (UK) Ltd., a KDAB Group company

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        Robbin
                        wrote on last edited by
                        #11

                        yeah, my bad, just noticed that too. And I haven't tried to compile it, it was using his code as starting point. He could percent encode the name only.....

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          goetz
                          wrote on last edited by
                          #12

                          [quote author="peppe" date="1314174967"]
                          This is completely nonsense. Not only that doesn't compile, but there's no QNetworkRequest(QByteArray) ctor
                          [/quote]

                          The compiler will call the non-explicit QString(QByteArray) constructor for this, unless QT_NO_CAST_FROM_ASCII is defined.

                          http://www.catb.org/~esr/faqs/smart-questions.html

                          1 Reply Last reply
                          0
                          • D Offline
                            D Offline
                            dangelog
                            wrote on last edited by
                            #13

                            [quote author="Volker" date="1314177476"]
                            [quote author="peppe" date="1314174967"]
                            This is completely nonsense. Not only that doesn't compile, but there's no QNetworkRequest(QByteArray) ctor
                            [/quote]

                            The compiler will call the non-explicit QString(QByteArray) constructor for this, unless QT_NO_CAST_FROM_ASCII is defined.
                            [/quote]

                            Nope -- QNetwokRequest wants a QUrl. There are two conversions to be made (QByteArray -> QString -> QUrl), and C++ forbids that (not to mention the fact that you can disable either of them with macros).

                            Software Engineer
                            KDAB (UK) Ltd., a KDAB Group company

                            1 Reply Last reply
                            0
                            • Q Offline
                              Q Offline
                              qwertyuiopearendil
                              wrote on last edited by
                              #14

                              Then what should i do?

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                andre
                                wrote on last edited by
                                #15

                                Constructing a valid QUrl to pass to QNetworkRequest sounds like a reasonable path to walk...

                                1 Reply Last reply
                                0
                                • Q Offline
                                  Q Offline
                                  qwertyuiopearendil
                                  wrote on last edited by
                                  #16

                                  It's what I'm trying to do...

                                  1 Reply Last reply
                                  0
                                  • D Offline
                                    D Offline
                                    dangelog
                                    wrote on last edited by
                                    #17

                                    [quote author="qwertyuiopearendil" date="1314180408"]Then what should i do?[/quote]

                                    As I said, dump HTTP headers and inspect them.

                                    Software Engineer
                                    KDAB (UK) Ltd., a KDAB Group company

                                    1 Reply Last reply
                                    0
                                    • G Offline
                                      G Offline
                                      goetz
                                      wrote on last edited by
                                      #18

                                      [quote author="peppe" date="1314177763"]
                                      Nope -- QNetwokRequest wants a QUrl. There are two conversions to be made (QByteArray -> QString -> QUrl), and C++ forbids that (not to mention the fact that you can disable either of them with macros).
                                      [/quote]

                                      Eek, you're right. I mixed up the parentheses. I need to do more LISP to get used to that ;-)

                                      http://www.catb.org/~esr/faqs/smart-questions.html

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        andre
                                        wrote on last edited by
                                        #19

                                        You might want to read the documentation for QUrl::fromUserInput then. It contains some more info on how to deal with string encodings and the likes.

                                        1 Reply Last reply
                                        0
                                        • Q Offline
                                          Q Offline
                                          qwertyuiopearendil
                                          wrote on last edited by
                                          #20

                                          Solved!!!
                                          Below the solution about my problem:

                                          @
                                          QString strUrl="http://myStore-dev.com/zip/mioFile%2_B.zip";

                                          QByteArray baUrl(strUrl.toAscii().data());

                                          QUrl tmpUrl1;
                                          tmpUrl1.setEncodedUrl(baUrl);
                                          iNetReply = iNetManager->get(QNetworkRequest(tmpUrl1));
                                          @

                                          Thanks to all.

                                          Bye bye.

                                          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