[Solved] QNetworkAccessManager empy reply next get fails



  • Hello,
    I have a strange problem.
    I want to download XML (with is result of query from WWW) and situation looks like this:

    • 1st GET() request always success
    • next request do success when previous reply data is not empty
    • next request do FAIL when previous data is empty

    By fail I mean nothing happens at all. Checked with Wireshark and no GET request is send to WWW so Qt just fall-back silently (no finished(), progress() etc is emited, dead silence on QNetworkReply / QNetworkAccessManager).

    WWW uses basic authentication, on first connect attempt I do recive authenticationRequired(QNetworkReply*,QAuthenticator*) signal and after authentication everything works fine as long as server do reply with data.

    I'm open to any suggestion.
    NOTE: code is ok, because every other WWW do reply correctly so it seams to me that it's Qt bug similar to this one: https://bugreports.qt.io/browse/QTBUG-5997

    Thanks in advance for reply.
    Best regards

    UPDATE:
    More info about situation:

    • QNetworkAccessManager GET -> finished() -> reply->readAll() NOT empty
    • QNetworkAccessManager GET -> finished() -> reply->readAll() NOT empty
      ...
    • QNetworkAccessManager GET -> finished() -> reply->readAll() IS empty
    • QNetworkAccessManager GET -> dead silence nothing happens at this point using reply->abort(); reply->close() nothing works. No finished() / progress() etc.


  • In free time I did more research and server reply with HTTP status 204. After receiving 204 next GET request does nothing.

    Update:
    situation 1
    QNetworkAccessManager ->get() ... reply HTTP 200
    QNetworkAccessManager ->get() ... reply HTTP 204
    QNetworkAccessManager ->get() ... nothing

    situation 2
    QNetworkAccessManager ->get() ... reply HTTP 204
    QNetworkAccessManager ->get() ... nothing

    So when QNetworkAccessManager get 204 next get() will fail.



  • Solution:
    There is something wrong with QNetworkAccessManager when HTTP 204 reply ("No content") is received. Probably timeout or internal connection state is not updated (i.e. class still thinks that connection / reply did not finished).

    To get around this don't use persistent connection Keep-alive but close each time.

        QNetworkRequest request;
        request.setUrl( url);
        ...
        request.setRawHeader("Connection", "close");
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.