QString BaseProxy::fetch(const QString& url, QString& referer, QStringList*a, QStringList*b, int cust) { if (cust) { printf("BASEPROXY: USING CUSTOM REQUEST\n"); } QString proto=url.section("//",0,0).toUpper(); if (proto!="HTTP:" && proto !="HTTPS:") { errorString="Protocol not supported"; return QString::null; } QString s=url.section("//",1); QString serv=s.section("/",0,0); QString doc="/"+s.section("/",1); if (serv.isEmpty()) return QString::null; QString res; if (proto=="HTTP:") res=fetchPage(serv,doc,referer,a,b, cust); else if (proto=="HTTPS:") res=fetchPageSSL(serv,doc,referer,a,b, cust); else { res=QString::null; qDebug() << "Unsupported protocol: " << proto; } referer=url; return res; }
void LoadPage::gotResponse() { qDebug() << "LoadPage::gotResponse"; QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender()); if (reply->error() == QNetworkReply::NoError) { int status = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); qDebug() << "LoadPage::gotResponse: status:" << status; QString r_url; switch (status) { case 301: case 302: case 307: r_url = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl().toString(); qDebug() << "LoadPage::gotResponse: redirected:" << r_url; fetchPage(r_url); break; default: qDebug() << "LoadPage::gotResponse: emit pageLoaded"; emit pageLoaded(reply->readAll()); } } else { qDebug() << "LoadPage::gotResponse: error:" << reply->error() << ":" << reply->errorString(); emit errorOcurred((int)reply->error(), reply->errorString()); } reply->deleteLater(); }