QNetworkAccessManager跳转URL处理(使用QNetworkRequest::RedirectionTargetAttribute获得跳转URL)
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(onFinished(QNetworkReply*)));
void MainClass::onFinished(QNetworkReply* reply)
{
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
QString strUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString();
qDebug() << "FINISHED" << statusCode;
switch (statusCode)
{
case 200: // OK
{
// process reply
if (!isLoggedIn())
storeAuthorization(reply);
switch (state)
{
case stGetCalendars:
{
parseCalendarList(reply);
break;
}
case stGetEvents:
{
parseEventList(reply);
break;
}
}
break;
}
case 302: // redirect (Location: [URL])
{
qDebug() << "redirected to" << locationOf(reply);
prepare(locationOf(reply));
manager->get(*lastRequest);
break;
}
case 400: // bad request
{
QMessageBox::warning(this, "Error", "Network error (HTTP400/Bad Request)");
break;
}
case 403: // permission denied
{
QMessageBox::warning(this, "Permission denied", "Username or password invalid");
break;
}
default:
{
QByteArray replyData = reply->readAll();
qDebug() << "Unknown response" << replyData;
break;
}
}
reply->deleteLater();
// do anything afterwards?
after(); // <-- next request via manager->get()
qDebug() << "request done";
}
http://blog.csdn.net/itjobtxq/article/details/8268675