Getting the HTTP standard response code from a QNetworkReply
-
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?
-
Have you tried "error()":http://doc.qt.nokia.com/4.7/qnetworkreply.html#error method?
-
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; }
@