Qt World Summit: Submit your Presentation

[SOLVED] QNetworkAccessManager failing to retrieve data

  • Edited: Environment
    Qt 4.7.4
    KDE 4.7.1
    Kubuntu 11.10

    I'm trying to pull back data from an url ("http://whirlpool.net.au":http://whirlpool.net.au), code as follows:

    void KWhirlMonView::refresh()
    QUrl url("http://whirlpool.net.au");
    QNetworkRequest request(url);

    reply = qnam.get(request);
    connect(reply, SIGNAL(finished()),
            this, SLOT(httpFinished()));
    connect(reply, SIGNAL(readyRead()),
            this, SLOT(httpReadyRead()));
    connect(reply, SIGNAL(downloadProgress(qint64,qint64)),
            this, SLOT(updateDataReadProgress(qint64,qint64)));
    connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
            this, SLOT(httpError(QNetworkReply::NetworkError)));


    void KWhirlMonView::httpFinished()
    kDebug() << "httpFinished - " << reply->errorString() << endl;
    QByteArray data = reply->readAll();
    QString s(data);
    kDebug() << s << endl;

    void KWhirlMonView::httpError ( QNetworkReply::NetworkError code )
    kDebug() << code << endl;


    the error slot always triggers with error code 203
    The error String is "Error downloading http://whirlpool.net.au - server replied: Not found"
    The data returned is : "<html><body>The requested resource could not be found.</body></html>"

    I can open the site fine with any browser and other windows SDK code (delphi + indy httpClient)

    Any suggestions?

    Thanks - Lindsay

  • Your first referenced link on this page here is broken (first line). It includes ")," .

  • I don't understand your point - thats just the forum software mangling the link I posted. You'll note the actual code I posted has the correct url - "http://whirlpool.net.au":http://whirlpool.net.au

  • ps - Thanks though! :)

  • Sorry, it is just a problem in your positing.
    In the first line of your post you have attached immediately after the link a ')' and a ','.
    If one tries to follow this link, one will get an error message. This is a problem of devnet.
    Unfortunately, it does not address your actual problem.

    [Edit] Someone has fixed it in the mean time.

  • That was me :) thanks for the heads up

  • I should add - tried the code with "http://google.com":http://google.com, that worked fine (retrieved the content)

  • Have you tried to use Wireshark or tcpdump to spot the difference between the two requests?
    What does qDebug() << reply->request()->url() say?

    Probably the site has some restrictions based on user agent or access pattern to block your request. At least they have some sense of "humor":http://whirlpool.net.au/index.php ;-)

  • Some error in code?
    I think
    @reply = qnam.get(request);@

    Should be
    @reply = qname->get(request);@

    you should check, like Lukas Geyer says to check your url reqest.

  • Thanks Lucas, that definietly got me on the right track - once I set the user agent to "Mozilla ..." etc I started getting info back. Now having problems with the cgi parameters but I'll sort that.

    Might have a word with the site admin about the UA requirement - doesn't seem neccessary ...

Log in to reply