PDA

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



yosva
9th September 2014, 10:53
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.

smaker85
23rd March 2015, 05:53
Have you solved this problem? Does anybody know the answer?

jefftee
23rd March 2015, 06:49
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?

yosva
26th March 2015, 18:42
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.

jefftee
26th March 2015, 18:50
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?

yosva
29th March 2015, 22:31
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.