we are using QtWebKit 4.7 and want to know when a frame load does a redirect.
At the moment we are counting the outgoing requests within a subclass of the QNetworkAccessManager, where we do overwrite createRequest.
This works in most cases fine, but when the first response is 301 or 302 (redirect), it is swallowed somewhere.
We simply request a url the following way:
QNetworkRequest request(QUrl("http://www.twitter.com")); // 301 to twitter.com
frame->load(request);
Handle the QNetworkReply yourself, get the status code from the reply and do a QWebFrame::setcontent.
QNetworkRequest request(QUrl("http://www.twitter.com")); // 301 to twitter.com
connect (frame->page()->networkAccessManager(), SIGNAL(finished(QNetworkReply*), this, SLOT(onFinished(QNetworkReply*));
frame->page()->networkAccessManager()->get(request);
[...]
void onFinished(QNetworkReply* reply)
{
if (reply->error() == QNetworkReply::NoError) {
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
switch (statusCode) {
case 301:
case 302:
case 307:
qDebug() << "redirected: " << reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl();
break;
case 200:
frame->setContent(reply->readAll());
break;
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With