while(!rpm_urlStack->isEmpty())
{
rpm_urlStack->pop();
bool returnVal = true;
QNetworkRequest request;
request.
setUrl(QUrl(urlForReq
));
request.setRawHeader("User-Agent", USER_AGENT.toUtf8());
request.setRawHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
request.setRawHeader("Accept-Language", "en-us,en;q=0.5");
request.setRawHeader("Connection", "Keep-Alive");
reply = m_networkManager->get(request);
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exit();
if(!loop.isRunning())
{
loop.exec();
}
RequestFinishedHandler(reply);
}
RequestFinishedHandler(QNetworkReply *reply)
{
if (reply->error() > 0) {
QNetworkReply::NetworkError networkError = reply->error();
QString err
= reply
->errorString
();
}
else {
QVariant vStatusCodeV
= reply
->attribute
(QNetworkRequest
::HttpStatusCodeAttribute);
QMutexLocker lock
(_pMutex
);
// _pMutex defined as class member char *buffer;
buffer = getCurrentDateTime();
out << buffer <<" "<< _sCurrentUrl << "\n";
lock.unlock();
if(vStatusCodeV.toInt() == 200)
{
data=reply->readAll();
ApiResponse.
append(QString::fromUtf8(data
));
}
}
reply->deleteLater();
}
while(!rpm_urlStack->isEmpty())
{
QString url = rpm_urlStack->top();
rpm_urlStack->pop();
QString urlForReq(url);
bool returnVal = true;
QNetworkRequest request;
request.setUrl(QUrl(urlForReq));
request.setRawHeader("User-Agent", USER_AGENT.toUtf8());
request.setRawHeader("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
request.setRawHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
request.setRawHeader("Accept-Language", "en-us,en;q=0.5");
request.setRawHeader("Connection", "Keep-Alive");
QEventLoop loop;
reply = m_networkManager->get(request);
connect(reply, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exit();
if(!loop.isRunning())
{
loop.exec();
}
RequestFinishedHandler(reply);
}
RequestFinishedHandler(QNetworkReply *reply)
{
if (reply->error() > 0) {
QNetworkReply::NetworkError networkError = reply->error();
QString err = reply->errorString();
}
else {
QVariant vStatusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
QMutexLocker lock(_pMutex); // _pMutex defined as class member
char *buffer;
buffer = getCurrentDateTime();
QTextStream out(m_file);
out << buffer <<" "<< _sCurrentUrl << "\n";
lock.unlock();
if(vStatusCodeV.toInt() == 200)
{
QString ApiResponse;
QByteArray data;
data=reply->readAll();
ApiResponse.append(QString::fromUtf8(data));
}
}
reply->deleteLater();
}
To copy to clipboard, switch view to plain text mode
Bookmarks