Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
4.7.0
-
None
Description
The attached example demonstrates the problem. It has been reproduced using Windows and Linux.
When using the following piece of code where username/password is set in the proxy object, everything works fine:
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy, "someHostName",somePort, "someUserName", "somePassword"));
However, if the code is changed to:
QNetworkProxy::setApplicationProxy(QNetworkProxy(QNetworkProxy::HttpProxy, "someHostName", somePort));
without passing username/password, and a dialog is popped up to get the username and password and pass it to the QAuthenticator as shown below then it does not work:
void HttpWindow::slotProxyAuthenticationRequired(const QNetworkProxy& proxy, QAuthenticator* authenticator) { QDialog dlg; Ui::Dialog ui; ui.setupUi(&dlg); dlg.adjustSize(); ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(url.host())); if (dlg.exec() == QDialog::Accepted) { authenticator->setUser(ui.userEdit->text()); authenticator->setPassword(ui.passwordEdit->text()); } }
These lines are shown in the output:
QNetworkAccessCache::addEntry: overriding active cache entry 'auth:proxy-http://...
QNetworkAccessCache::addEntry: overriding active cache entry 'auth:proxy-http://...
QNetworkAccessCache::addEntry: overriding active cache entry 'auth:proxy-http://...'
It can be fixed as follows:
void HttpWindow::slotProxyAuthenticationRequired(const QNetworkProxy& proxy, QAuthenticator* authenticator) { QDialog dlg; Ui::Dialog ui; ui.setupUi(&dlg); dlg.adjustSize(); ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(url.host())); if (dlg.exec() == QDialog::Accepted) { authenticator->setUser(ui.userEdit->text()); authenticator->setPassword(ui.passwordEdit->text()); QNetworkProxy p(proxy); p.setUser(ui.userEdit->text()); p.setPassword(ui.passwordEdit->text()); QNetworkProxy::setApplicationProxy(p); }
}
but that's a dirty hack ...