webview1.page().setNetworkAccessManager( m_pMyNetworkMgr );//-- есть доступ к траффику!
/*virtual*/ QNetworkReply* MyNetworkAccessManager::createRequest( Operation op, const QNetworkRequest& req, QIODevice *outgoingData ){ QNetworkRequest myReq = cloneRequest( req );//-- copy data from const QNetworkRequest& req QString strUA = ...;//-- custom value for User-Agent QString strRef = ...;//-- custom value for Referer myReq.setRawHeader( "User-Agent", strUA.toUtf8() ); myReq.setRawHeader( "Referer", strRef.toUtf8() ); return QNetworkAccessManager::createRequest( op, myReq, outgoingData );}
Javaclass CorrectNetworkAccessManager extends QNetworkAccessManager{ @Override protected QNetworkReply createRequest(Operation op, QNetworkRequest request, QIODevice outgoingData) { QNetworkRequest myReq = new QNetworkRequest(request); String strUA = "myAgent"; String strRef = "http://www.prog.org.ru/index.php?topic=11629.msg71840#msg71840"; myReq.setRawHeader( new QByteArray("User-Agent"), new QByteArray(strUA) ); myReq.setRawHeader( new QByteArray("Referer"), new QByteArray(strRef) ); return super.createRequest(op, myReq, outgoingData); }}
Javathis.page.page().setNetworkAccessManager(new CorrectNetworkAccessManager());this.page.load(url);