I can not do QNetworkAccessManager::createRequest finalize request. I tried
finished(QNetworkRequest)
finished(QNetworkRequest)
To copy to clipboard, switch view to plain text mode
, but nothing happens, see how was the WebInspector:
7IA6s.png
The request is pending and never ends.
What am I doing wrong?
My code:
QNetworkReply
* myNAM
::createRequest(Operation op,
const QNetworkRequest
&request,
QIODevice *outgoingData
){ QNetworkAccessManager *n = new QNetworkAccessManager();
QNetworkRequest req(request.url());
const QList<QByteArray>a = request.rawHeaderList();
int j = a.length();
int i=0;
for(;i<j;++i){
req.setRawHeader(a[i],request.rawHeader(a[i]));
}
QList<QNetworkCookie> cookies = CookiesGlobals->cookiesForUrl(request.url());
n->cookieJar()->setCookiesFromUrl(cookies,request.url());
QNetworkReply *p;
if(op==PostOperation) {
p = n->post(req, data);
} eles {
p = n->get(req);
}
connect(p, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
QVariant statusCode
= p
->attribute
(QNetworkRequest
::HttpStatusCodeAttribute);
if (statusCode.isValid()){
int status = statusCode.toInt();
qDebug() << "FB: " status;
} else {
qDebug() << "FB: statusCode isInvalid";
}
finished(p);
return p;
}
QNetworkReply * myNAM::createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData){
QNetworkAccessManager *n = new QNetworkAccessManager();
QNetworkRequest req(request.url());
const QList<QByteArray>a = request.rawHeaderList();
int j = a.length();
int i=0;
for(;i<j;++i){
req.setRawHeader(a[i],request.rawHeader(a[i]));
}
QList<QNetworkCookie> cookies = CookiesGlobals->cookiesForUrl(request.url());
n->cookieJar()->setCookiesFromUrl(cookies,request.url());
QNetworkReply *p;
if(op==PostOperation) {
const QByteArray data = outgoingData->readAll();
p = n->post(req, data);
} eles {
p = n->get(req);
}
QEventLoop loop;
connect(p, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
QVariant statusCode = p->attribute(QNetworkRequest::HttpStatusCodeAttribute);
if (statusCode.isValid()){
int status = statusCode.toInt();
qDebug() << "FB: " status;
} else {
qDebug() << "FB: statusCode isInvalid";
}
finished(p);
return p;
}
To copy to clipboard, switch view to plain text mode
Bookmarks