[Solved] QNetWorkRequest



  • In Google Chrome, when an error occurs in the request to the server, the Google Chrome tries a new request, see LOG wireshark:

    !http://i.stack.imgur.com/qy0jL.png(wireshark log)!

    I'm developing a full browser in QT and realized that if a request fails the "QWebView" has the same behavior as Google Chrome.

    How can I reimplement the QNetWorkRequest/QNetWorkAccessManager to work like the conventional browsers?

    Help me please.

    @myWebPage *myWP = new myWebPage();
    myWP->setForwardUnsupportedContent(true);
    myWP->setNetworkAccessManager(m_network);
    ui->myWebView->setPage(myWP);

    if(q!=true) {
    settings = QWebSettings::globalSettings();

    settings->setAttribute( QWebSettings::OfflineWebApplicationCacheEnabled,true );
    settings->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls,true );
    settings->setAttribute( QWebSettings::OfflineStorageDatabaseEnabled,true );
    settings->setAttribute( QWebSettings::LocalContentCanAccessFileUrls,true );
    settings->setAttribute( QWebSettings::LocalStorageEnabled,true );
    settings->setAttribute( QWebSettings::JavascriptCanOpenWindows,true );
    settings->setAttribute( QWebSettings::JavascriptCanCloseWindows,true );
    settings->setAttribute( QWebSettings::JavascriptEnabled,true );
    
    settings->setAttribute( QWebSettings::PluginsEnabled,true );
    settings->setAttribute( QWebSettings::JavaEnabled,false );//Desabilita java
    settings->setAttribute( QWebSettings::DeveloperExtrasEnabled,true );
    settings->setAttribute( QWebSettings::AutoLoadImages, true );
    
    
    settings->setAttribute( QWebSettings::DnsPrefetchEnabled, true );
    settings->setAttribute( QWebSettings::LocalStorageDatabaseEnabled, true );
    settings->setAttribute( QWebSettings::AcceleratedCompositingEnabled, true );
    settings->setAttribute( QWebSettings::JavascriptCanAccessClipboard, false );
    settings->setAttribute( QWebSettings::ScrollAnimatorEnabled, true );
    
    settings->setAttribute( QWebSettings::PrintElementBackgrounds, false );
    
    settings->setOfflineWebApplicationCachePath( QString(localStorage+"/appcache") );
    settings->enablePersistentStorage( QString(localStorage+"/persistent") );
    settings->setOfflineStoragePath( QString(localStorage+"/offlinestorage") );
    settings->setLocalStoragePath( QString(localStorage+"/storage") );
    settings->setIconDatabasePath( QString(localStorage+"/icons") );
    
    settings->setMaximumPagesInCache( 99999 );
    settings->setObjectCacheCapacities( 0,99999,99999 );
    
    settings->setOfflineWebApplicationCacheQuota( 5*1024*1024 );
    settings->setOfflineStorageDefaultQuota( 5*1024*1024 );
    

    }
    connect(ui->myWebView->page(), SIGNAL(downloadRequested(QNetworkRequest)), this, SLOT(Download(QNetworkRequest)));
    connect(ui->myWebView->page(), SIGNAL(unsupportedContent(QNetworkReply*)), this, SLOT(unsupportedToDownload(QNetworkReply*)));
    connect(ui->myWebView->page(), SIGNAL(printRequested(QWebFrame*)), this, SLOT(printFrame(QWebFrame*)));@


  • Moderators

    i don't know if there is a setting for retry on failure (i'm in hurry right now can't check).
    But what comes in my mind is you can subclass QNetworkAccessManager and reimplement
    "createRequest()":http://qt-project.org/doc/qt-4.8/qnetworkaccessmanager.html#createRequest and return a new QNetworkReply object. And write the contents to it of the "orginal request". If the original request fails, try it again ,... on success write all the data to the custom created QNetworkReply.

    Because i think you can't override QtWebkit's error handling on a failed request.



  • I did this:
    @QNetworkReply * myNAM::createRequest(Operation op, const QNetworkRequest &request, QIODevice *outgoingData){
    if(op==PostOperation) {
    qDebug() << "isPost";
    QNetworkAccessManager *n = new QNetworkAccessManager();
    QFile delta("teste.txt");
    if(delta.open(QIODevice::WriteOnly)){
    delta.write(outgoingData->readAll());
    delta.close();
    }
    QNetworkReply *p = n->post(request,outgoingData);
    //qDebug() << p->url();
    //qDebug() << "newRequest";
    p->waitForReadyRead(8000);
    qDebug() << "readyRequest";
    if(p->isReadable()){
    qDebug() << "readyRequest is ready";
    return QNetworkAccessManager::createRequest(op, p->request(), outgoingData);
    }
    p->abort();
    }
    return QNetworkAccessManager::createRequest(op, request, outgoingData);
    }@

    But I can not get the POST data to arrive at the requested page.

    There comes a post empty (eg the response of PHP):
    code:
    @<?php
    print_r($_POST);
    ?>@

    Response (output), POST returned empty.:
    @Array();@

    Please help me make this code work!




Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.