Try changing your answerFinished slot to look like this:
QByteArray bytes = reply->readAll(); QString str = QString::fromUtf8(bytes.data(), bytes.size()); int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
You can then print the statusCode to see if you get a 200 response:
qDebug() << QVariant(statusCode).toString();
If you get a 302 response, you get a status redirect. You will need to handle it as follows:
if(statusCode == 302) { QUrl newUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl(); qDebug() << "redirected from " + replyUrl + " to " + newUrl.toString(); QNetworkRequest newRequest(newUrl); manager->get(newRequest); return; }
I return when I encounter a status code of 302, since I do not want the rest of the method to be executed.
Hope this helps!
Cameron tinker
source share