QNetworkAccessManager doesn't download whole web page

  • Hi. I'm trying to donwload page via http using QNetworkAccessManager
    I store data in QByteArray and append readAll() from respective QNetworkReply object on each call of readyRead signal

    but when I check QByteArray content on finished signal of QNetworkAccessManager, it contains not whole page, it is cut in a certain place.
    I see there is a kind of limitation, but I can't find the way to avoid it

  • Did you really read the last chunk?

    finished() is emitted as soon as the request is done from a protocol perspective. You may have pending data in the reply that you have not read yet. It's good practice to call readAll() in your slot connected to finished() a last time to get the last chunk of data.

    If your data is not big or you do not need the data chunkwise as soon as possible, you can have QNetworkReply collect the data and read the whole page after finished() with readAll(). See "QNetworkReply::finished() ":http://doc.qt.nokia.com/stable/qnetworkreply.html#finished for some details.

  • I tried doing only readAll() on QNetworkAccessManager finished signal, and it downloads the same exact piece of page!
    is there any significant difference between QNetworkAccessManager finished and QNetworkReply finished?

  • The finished signal of QNetworkReply is connected to a private slot of QNetworkAccessManager which in turn immediately emits finished(QNetworkReply*). So, no, there is no significant difference.

    As things work for most of the other people, it would be handy, if you could provide us a small, complete, compilable and running example that demonstrates the error and that we can run on our boxes.

  • Well thr code is as following
    void bot::recieveId() // this function initiates request
    manager->get(QNetworkRequest(QUrl("http://qt.nokia.com")));//it's not actual URL, but problem is the same

    void bot::idRecieved(QNetworkReply _reply) // this slot dumps the whole data
    manager and rawData are QNetworkAccessManager (instantiated in counstructor) and QByteArray (static)
    the last thing I have in console is
    <li><a href="http://qt.nokia.com/developer/eclipse-integration">Eclipse plug-in</a></li>

    while there is a hundred or more strings after

  • I just tried and it works for me. I get the complete page.

    I'm on Mac OS X 10.6, Qt 4.7.0.

    Do you have any proxy settings in your program? Or some corporate hidden proxy inbetween? Can you get the page correctly with another tool on the command line, eg.

    curl http://qt.nokia.com

  • well, I think I found the answer. I tried some operations with rawData (like finding </html> tag) and everything was ok. I guess it's just a limitation of qDebug()

  • Hi volker,

    I am using QNAM to download a XML file from server but getting "connection timed out" error message in reply. In your previous post you were asking whether Kxyu is using proxy in his program. My program is behind a corporate proxy, can it cause this issue? If yes, could you please let me know how to resolve the problem?

    Note: Through browser I can access the page successuflly

  • What's the point of necroposting? Please, start a brand new thread with all the relevant information.

Log in to reply