Results 1 to 5 of 5

Thread: (Solved) QNetworkAccessManager and http-stream without headers

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question (Solved) QNetworkAccessManager and http-stream without headers

    Hello Folks,

    I'am using QT version 4.6.3 under debian 6.0.3. (Compiling using qmake and make, gcc version 4.4.5 (Debian 4.4.5-8))

    To read from a measuring system a data stream using http and some additional data from html-pages i tried to use QNetworkAccessManager via GET (QNetworkRequest) and QNetworkReply.

    This runs flawless with the html-Pages.

    Qt Code:
    1. reply = qnam.get(QNetworkRequest(url));
    2. connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
    3. this, SLOT(httpError(QNetworkReply::NetworkError)));
    4. connect(reply, SIGNAL(readyRead()),
    5. this, SLOT(httpReadyRead()));
    6. connect(reply, SIGNAL(finished()),
    7. this, SLOT(httpFinished()));
    To copy to clipboard, switch view to plain text mode 

    Trying to read the stream the readyRead-routine will not run. To figure out what happened I also connected the error-routine. The reported error is error #2: RemoteHostClosedError.

    However, WGET can read and save the stream:
    Qt Code:
    1. wget -S HOST:PORT
    2. --2012-04-27 13:36:46-- HOST:PORT
    3. Trying to connec to HOST:PORT... connected.
    4. HTTP-Request sent, waiting for reply...200 No Headers, assuming HTTP/0.9.
    5. Length: not specified
    6. Saving to »index.html«
    To copy to clipboard, switch view to plain text mode 

    Firefox also can save the stream.

    A longer google-search found no appropriate answers. Only some ssl-related stuff, what does not relate to my problem, as far as I can see. What I have found in QT-Sources (4.7.0, in 4.6.0 it was not there, if it is in 4.6.3 I do not know): Inside qhttpnetworkconnectionchannel.cpp ( see arrows --> in code):

    Qt Code:
    1. case QAbstractSocket::RemoteHostClosedError:
    2. // try to reconnect/resend before sending an error.
    3. // while "Reading" the _q_disconnected() will handle this.
    4. if (state != QHttpNetworkConnectionChannel::IdleState && state != QHttpNetworkConnectionChannel::ReadingState) {
    5. if (reconnectAttempts-- > 0) {
    6. closeAndResendCurrentRequest();
    7. return;
    8. } else {
    9. errorCode = QNetworkReply::RemoteHostClosedError;
    10. }
    11. } else if (state == QHttpNetworkConnectionChannel::ReadingState) {
    12. if (!reply->d_func()->expectContent()) {
    13. // No content expected, this is a valid way to have the connection closed by the server
    14. return;
    15. }
    16. if (reply->contentLength() == -1 && !reply->d_func()->isChunked()) {
    17. --> // There was no content-length header and it's not chunked encoding,
    18. --> // so this is a valid way to have the connection closed by the server
    19. return;
    20. }
    21. // ok, we got a disconnect even though we did not expect it
    22. errorCode = QNetworkReply::RemoteHostClosedError;
    23. } else {
    24. errorCode = QNetworkReply::RemoteHostClosedError;
    25. }
    26. break;
    To copy to clipboard, switch view to plain text mode 

    Does that mean, that QNAM believes that an answer without headers and without chunking is a HostClosed situation and ends the connection itself?

    I'am at a loss at the moment, because I have developed my source code with via WGET temporarily stored data. My local webserver certainly added headers and length. Can someone give some deeper insights into QNAM, why that is happening?

    I'am working around the problem for now, wget-ing packages of the stream and feeding to my program but that is a bad hack because I loose temporal coherence on the data.

    Cheers,
    Kai
    Last edited by muehle.kai; 2nd May 2012 at 12:54. Reason: Solved

Similar Threads

  1. Create QNetworkRequest from QString(http headers)
    By davidpmp in forum Qt Programming
    Replies: 1
    Last Post: 9th December 2011, 22:45
  2. QNetworkAccessManager and http redirection
    By grayfox in forum Qt Programming
    Replies: 5
    Last Post: 8th July 2011, 17:24
  3. HTTP Post from QNetworkAccessManager - no data sent
    By secureboot in forum Qt Programming
    Replies: 1
    Last Post: 13th April 2011, 18:46
  4. QNetworkAccessManager Http Basic Authentication?
    By jloundy in forum Qt Programming
    Replies: 5
    Last Post: 29th December 2010, 00:19
  5. get network stream with QNetworkAccessManager
    By Remco in forum Qt Programming
    Replies: 0
    Last Post: 26th August 2010, 16:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.