QNetworkReply results in "Connection closed"
-
Hello Friends,
I want to get page source of the url requested.
I used code as:
@ /* create QNetworkAccessManager obj
* to send network requests and receive replies*/
QNetworkAccessManager* objNetAccessManager = new QNetworkAccessManager(this);/* Connect signal slot for getting page source of requested url */ connect(objNetAccessManager, SIGNAL(finished(QNetworkReply*)),this, SLOT(getPageSource(QNetworkReply*))); try { QNetworkRequest req; req.setUrl(QUrl(url)); /* for getting data and headers of requesrt sent */ QNetworkReply *reply = objNetAccessManager->get(req); connect(reply, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(slotError(QNetworkReply::NetworkError))); connect(reply, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(slotSslErrors(QList<QSslError>))); /* QNetworkReply and related classes are asynchronous and * doesn’t offer a blocking API and * requires an event loop to be running. * We enter a local QEventLoop, and when the reply has finished, * the local event loop quits. */ QEventLoop loop; connect(reply, SIGNAL(finished()), &loop, SLOT(quit())); loop.exec(); // this->thread()->sleep(3); } catch(std::exception &e) { qFatal("Error %s sending event ",e.what() ); }
getPageSource(QNetworkReply* reply)
{
//*Get pageSource from requested URL//
QString pageSource = QString::fromUtf8(reply->readAll());
}
@But I am getting pageSource as "Connection closed".
or
"Error downloading http://... - server replied: Not Acceptable"Please help me to resolve this.