Getting the HTTP standard response code from a QNetworkReply
-
wrote on 10 Aug 2011, 04:19 last edited by
I am working on some code to get an image from a web server using QNetworkReply. Since there is security to be concerned with, I need to look at the HTTP standard response code to determine if the result is a clean 200 or some type of error. How exactly do I get the the HTTP standard response code?
-
wrote on 10 Aug 2011, 07:41 last edited by
Have you tried "error()":http://doc.qt.nokia.com/4.7/qnetworkreply.html#error method?
-
wrote on 10 Aug 2011, 08:01 last edited by
The raw response code is available as an integer using the QNetworkReply::attribute(QNetworkRequest::HttpStatusCodeAttribute) method.
-
wrote on 10 Aug 2011, 09:52 last edited by
Connect a slot up to the QNetworkReply::metaDataChanged() signal. Then in that slot you can check what you need:
@
QVariant statusCode = reply->attribute( QNetworkRequest::HttpStatusCodeAttribute );
if ( !statusCode.isValid() )
return;int status = statusCode.toInt(); if ( status != 200 ) { QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString(); qDebug() << reason; }
@
2/4