Results 1 to 6 of 6

Thread: How to make QNetworkReply read all received data EVEN IF http status is not 200 OK

  1. #1
    Join Date
    Jul 2011
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default How to make QNetworkReply read all received data EVEN IF http status is not 200 OK

    Hi!

    My problem is the following:

    Response of QNetworkReply::readAll is empty when QNetworkReply::error() != NoError. Is this normal?

    I've readed doc relating QIODevice::readAll:
    This function has no way of reporting errors; returning an empty QByteArray() can mean either that no data was currently available for reading, or that an error occurred.
    That mean that every time http status is different from 200 OK QNetworkReply is unable to deliver other info that headers in response??

    I've a Node+Express server that always send a detailed --json-- description in case of http status is different from 200; I cant get this description from my Qt client base on QNAM.

    How can I change this behavior, I mean, make QNetworkReply read all received data EVEN IF http status is not 200 OK?

    Qt version is 5.3, OS Win 7 64b.

    Thanks a lot for your help.

  2. #2

    Default Re: How to make QNetworkReply read all received data EVEN IF http status is not 200 O

    Have you solved this problem? Does anybody know the answer?

  3. #3
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: How to make QNetworkReply read all received data EVEN IF http status is not 200 O

    QIODevice::readAll() will return all data returned with the request, regardless of the HTTP status code. If you're not receiving any data, it's because none was returned or you may have already read the data. i.e. Do you have a slot connected to QIODevice::readyRead() that may have already read data?

    What is the http status code, error() and errorString() you are receiving for the request?
    Last edited by jefftee; 23rd March 2015 at 07:24.

  4. #4
    Join Date
    Jul 2011
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to make QNetworkReply read all received data EVEN IF http status is not 200 O

    Hi! I've not very much time in this moment, but this week-end I'll review my code and prepare a demo if needed to prove the bizarre behavior of QNAM.
    By the moment my workaround is just not to send any body when status != 200 (by the way, is not exactly 200 but any not error code) but use the REASON header field.

    Yovanis.

  5. #5
    Join Date
    Dec 2009
    Location
    New Orleans, Louisiana
    Posts
    791
    Thanks
    13
    Thanked 153 Times in 150 Posts
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: How to make QNetworkReply read all received data EVEN IF http status is not 200 O

    I have done lots of work with QNetworkAccessManager and APIs like Amazon Web Services and flickr and I can assure you that I can successfully receive the response data when the http status code is >= 400.

    What is the web service you are consuming and what is the documented response expected when you receive an error?

  6. #6
    Join Date
    Jul 2011
    Posts
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to make QNetworkReply read all received data EVEN IF http status is not 200 O

    Jefftee is right, there is not problem with QNAM, I receive my body in all case. Sorry, and thanks My mistake was maybe a problem parsing json, not QNAM receiving raw data.

Similar Threads

  1. Replies: 2
    Last Post: 11th April 2013, 23:20
  2. Replies: 0
    Last Post: 22nd October 2012, 13:39
  3. Check http server status (inline/offline) with pyqt
    By fkili in forum Qt Programming
    Replies: 1
    Last Post: 9th October 2012, 01:06
  4. Methods to display received data
    By pupqt in forum Qt Programming
    Replies: 3
    Last Post: 18th April 2011, 10:50
  5. Replies: 2
    Last Post: 6th November 2010, 06:06

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.