A wrapper class for automatically handling HTTP redirects.
Use this class to wrap your QNetworkReply object that you would get on initiating a request. Once the final url (after redirects) is reached, it emits the finished(QNetworkReply *).
The parameter of the signal is the final reply object representing the last redirect.
void finished(QNetworkReply *reply): Emitted on receiving the final (non-redirect) response from the servervoid redirected(const QUrl &url): Emitted on every redirectvoid error(QNetworkReply::NetworkError code): RelayedQNetworkReplyerror signalvoid redirectError(QtNetworkReplyEx::RedirectError error): Emitted on encountering a redirect related error
The following errors can occur on redirects:
QtNetworkReplyEx::TooManyRedirects: Set when total number of redirects exceeds the maximum allowed redirects (QtNetworkReplyEx::maxRedirects()). Default is set to 10.QtNetworkReplyEx::UnsecureRedirect: Set when a redirect occurs from a secure (https) to a unsecure (http) connection andQtNetworkReplyEx::allowUnsecureRedirect()isfalse.QtNetworkReplyEx::InvalidRedirectProto: If rediect url's protocol is anything other than http ot https.
...
QtNetworkReplyEx redirector(manager->get(networkRequest), this);
connect(&redirector, SIGNAL(finished(QNetworkReply*)),
this, SLOT(onFinished(QNetworkReply*)));
connect(&redirector, SIGNAL(redirected(QUrl)),
this, SLOT(onRedirected(QUrl)));
connect(&redirector, SIGNAL(redirectError(QtNetworkReplyEx::RedirectError)),
this, SLOT(onRedirectError(QtNetworkReplyEx::RedirectError)));
connect(&redirector, SIGNAL(error(QNetworkReply::NetworkError)),
this, SLOT(onError(QNetworkReply::NetworkError)));
...
...
void onFinished(QNetworkReply *reply)
{
...
qDebug() << "Original url is" << redirector.url();
qDebug() << "Final url is" << reply->url();
...
}