I'm confused then by the QT exaple in
http://doc.trolltech.com/4.4/network-http.html
I followed the QT example where they set the password in the slot connected to the QHttp signal authenticationRequired(). I copied the QT example slot function below.
void HttpWindow
::slotAuthenticationRequired(const QString &hostName, quint16, QAuthenticator
*authenticator
) {
Ui::Dialog ui;
ui.setupUi(&dlg);
dlg.adjustSize();
ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(hostName));
if (dlg.
exec() == QDialog::Accepted) { authenticator->setUser(ui.userEdit->text());
authenticator->setPassword(ui.passwordEdit->text());
}
}
void HttpWindow::slotAuthenticationRequired(const QString &hostName, quint16, QAuthenticator *authenticator)
{
QDialog dlg;
Ui::Dialog ui;
ui.setupUi(&dlg);
dlg.adjustSize();
ui.siteDescription->setText(tr("%1 at %2").arg(authenticator->realm()).arg(hostName));
if (dlg.exec() == QDialog::Accepted) {
authenticator->setUser(ui.userEdit->text());
authenticator->setPassword(ui.passwordEdit->text());
}
}
To copy to clipboard, switch view to plain text mode
When I looked at the example's header response handler below, it does not have any case for authentication required. So perhaps the example is incorrect? Should it have a case 401 Unauthorized? I understand what you are saying about handling the error manually, but I'd sure like to know how QT's example is supposed to work.
{
switch (responseHeader.statusCode()) {
case 200: // Ok
case 301: // Moved Permanently
case 302: // Found
case 303: // See Other
case 307: // Temporary Redirect
// these are not error conditions
break;
default:
tr("Download failed: %1.")
.arg(responseHeader.reasonPhrase()));
httpRequestAborted = true;
progressDialog->hide();
http->abort();
}
}
void HttpWindow::readResponseHeader(const QHttpResponseHeader &responseHeader)
{
switch (responseHeader.statusCode()) {
case 200: // Ok
case 301: // Moved Permanently
case 302: // Found
case 303: // See Other
case 307: // Temporary Redirect
// these are not error conditions
break;
default:
QMessageBox::information(this, tr("HTTP"),
tr("Download failed: %1.")
.arg(responseHeader.reasonPhrase()));
httpRequestAborted = true;
progressDialog->hide();
http->abort();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks