I'm having problems getting through a proxy. If I use the following code.
QWebView a;
a.
load(QUrl("http:\\google.co.uk"));
a.show();
QWebView a;
a.load(QUrl("http:\\google.co.uk"));
a.show();
To copy to clipboard, switch view to plain text mode
The request fails, because I'm behind a proxy. Which is fine and I understand that. So if I amend the code to :
QNetworkProxyFactory::setUseSystemConfiguration ( true) ;
QWebView a;
a.
load(QUrl("http:\\google.co.uk"));
a.show();
QNetworkProxyFactory::setUseSystemConfiguration ( true) ;
QWebView a;
a.load(QUrl("http:\\google.co.uk"));
a.show();
To copy to clipboard, switch view to plain text mode
Everything works fine. I see the google page and I'm not prompted to input my proxy user name or password.
Now this is where I have my problem. I don't want to use a GUI. I'm trying to automate a process at work so I thought I would use QNetworkAccessManager to the same result.
So heres my code :
QUrl a
("http://google.co.uk");
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkProxyQuery npq(a);
QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::systemProxyForQuery(npq);
if (listOfProxies.count() !=0){
manager->setProxy(listOfProxies.at(0));
std::cerr << "Using Proxy " << listOfProxies.at(0).hostName().toStdString() << "\n";
}
}
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(outPutPage(QNetworkReply*)));
manager->get(QNetworkRequest(a));
QUrl a("http://google.co.uk");
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
QNetworkProxyQuery npq(a);
QList<QNetworkProxy> listOfProxies = QNetworkProxyFactory::systemProxyForQuery(npq);
if (listOfProxies.count() !=0){
if (listOfProxies.at(0).type() != QNetworkProxy::NoProxy) {
manager->setProxy(listOfProxies.at(0));
std::cerr << "Using Proxy " << listOfProxies.at(0).hostName().toStdString() << "\n";
}
}
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(outPutPage(QNetworkReply*)));
manager->get(QNetworkRequest(a));
To copy to clipboard, switch view to plain text mode
Now without a proxy this code works fine and I see the HTML printed to the screen. However when running behind a proxy (that requires authentication) I see the code telling me its "Using Proxy" but the code fails even if I supply a valid username and password, it just keeps reporting that the proxy requires authentication. I have tried many different combinations, using QNetworkProxyFactory::setUseSystemConfiguration ( true) ; setting the application proxy.
Does anyone have any idea how I might resolve this. Or is there a class I can use in the QWebKit that doesn't have the over head of rendering. I'm only interested in the data being sent a received. Or doesn't anyone know what the QWebKit class does differently to QNetworkAccessManager::setProxy?
All help will be appreciated.
Regards
Dan
Bookmarks