QNetworkReply
* myNAM
::createRequest(Operation op,
const QNetworkRequest
&request,
QIODevice *outgoingData
){ if(op==PostOperation) {
QNetworkAccessManager *n = new QNetworkAccessManager();
QNetworkRequest req(request.url());
const QList<QByteArray>a = request.rawHeaderList();
int i = 0; int j = a.length();
for(;i<j;i++){
qDebug() << a[i] << ": " << request.rawHeader(a[i]);
req.setRawHeader(a[i],request.rawHeader(a[i]));
}
if(contentType!=""){
req.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
}
QNetworkReply *p = n->post(req,data);
//wait request finish
connect(p, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
if(/*the attempt limit*/){
if(p->errorString()=="Unknown error") {
//tries to resend again when the error occurs "Unknown Error"
return myNAM::createRequest(op, request, outgoingData);
}
//sends request ready.
return QNetworkAccessManager::createRequest(op, p->request(), outgoingData);
}
}
//send normal mode, GET, PUT and DELETE or chance the retry limit has finished
return QNetworkAccessManager::createRequest(op, request, outgoingData);
}
QNetworkReply * myNAM::createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData){
if(op==PostOperation) {
QNetworkAccessManager *n = new QNetworkAccessManager();
QString contentType = "";
QNetworkRequest req(request.url());
const QList<QByteArray>a = request.rawHeaderList();
int i = 0; int j = a.length();
for(;i<j;i++){
qDebug() << a[i] << ": " << request.rawHeader(a[i]);
req.setRawHeader(a[i],request.rawHeader(a[i]));
}
if(contentType!=""){
req.setHeader(QNetworkRequest::ContentTypeHeader, contentType);
}
const QByteArray data = outgoingData->readAll();
QNetworkReply *p = n->post(req,data);
//wait request finish
QEventLoop loop;
connect(p, SIGNAL(finished()), &loop, SLOT(quit()));
loop.exec();
if(/*the attempt limit*/){
if(p->errorString()=="Unknown error") {
//tries to resend again when the error occurs "Unknown Error"
return myNAM::createRequest(op, request, outgoingData);
}
//sends request ready.
return QNetworkAccessManager::createRequest(op, p->request(), outgoingData);
}
}
//send normal mode, GET, PUT and DELETE or chance the retry limit has finished
return QNetworkAccessManager::createRequest(op, request, outgoingData);
}
To copy to clipboard, switch view to plain text mode
Bookmarks