this.webPage.page().setNetworkAccessManager(new CorrectNetworkAccessManager(this.ip, this.port));
this.webPage.load(this.url);
this.webPage.page().setNetworkAccessManager(new CorrectNetworkAccessManager(this.ip, this.port));
this.webPage.load(this.url);
To copy to clipboard, switch view to plain text mode
Code of class CorrectNetworkAccessManager (which extends QNetworkAccessManager):
class CorrectNetworkAccessManager extends QNetworkAccessManager
{
int _port;
String _ip, userAgent, acceptLanguage, acceptCharset;
public CorrectNetworkAccessManager(String ip, int port)
{
this._ip = ip;
this._port = port;
}
@Override
protected QNetworkReply createRequest
(Operation op, QNetworkRequest request,
QIODevice outgoingData
) {
QNetworkRequest myReq = new QNetworkRequest(request);
/*This show url of each resource of webpage. If number of threads is 10 and webpage contains, for example, gif-image
(<img src="myimage.gif">), this method show us only ONE gif-image url, and it is necessary to do, that 10 showed. I.e.
to abolish cache for this picture. However, if webpage contains php-page, it show 10 times! (because php-page not
caching) */
System.out.println(myReq.url());
this.userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko)";
this.acceptLanguage = "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4";
this.acceptCharset = "windows-1251,utf-8;q=0.7,*;q=0.3";
}
}
class CorrectNetworkAccessManager extends QNetworkAccessManager
{
int _port;
String _ip, userAgent, acceptLanguage, acceptCharset;
public CorrectNetworkAccessManager(String ip, int port)
{
this._ip = ip;
this._port = port;
}
@Override
protected QNetworkReply createRequest(Operation op, QNetworkRequest request, QIODevice outgoingData)
{
QNetworkRequest myReq = new QNetworkRequest(request);
/*This show url of each resource of webpage. If number of threads is 10 and webpage contains, for example, gif-image
(<img src="myimage.gif">), this method show us only ONE gif-image url, and it is necessary to do, that 10 showed. I.e.
to abolish cache for this picture. However, if webpage contains php-page, it show 10 times! (because php-page not
caching) */
System.out.println(myReq.url());
this.userAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko)";
this.acceptLanguage = "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4";
this.acceptCharset = "windows-1251,utf-8;q=0.7,*;q=0.3";
myReq.setRawHeader( new QByteArray("User-Agent"), new QByteArray(this.userAgent) );
myReq.setRawHeader( new QByteArray("Accept-Charset"), new QByteArray(this.acceptCharset) );
myReq.setRawHeader( new QByteArray("Accept-Language"), new QByteArray(this.acceptLanguage) );
}
}
To copy to clipboard, switch view to plain text mode
How to abolish cach for image? Thanks for answers.
Bookmarks