Пишу программу, которая должна работать по протоколу http через прокси-сервер (в моем случае - через Microsoft ISA Server). Для этого юзаю класс QNetworkProxy примерно так: | Код | void MainWindow::downloadLine() { QUrl url("http://www.azbet.com/eventsxml.aspx?AspxAutoDetectCookieSupport=1"); QFileInfo fileInfo(url.path()); QString fileName = fileInfo.fileName(); QDateTime now = QDateTime::currentDateTime(); fileName = "azbet" + now.toString("yyyyMMddhhmm") + ".xml";
if (QFile::exists(fileName)) { if (QMessageBox::question(this, tr("HTTP"), tr("There already exists a file called %1 in " "the current directory. Overwrite?").arg(fileName), QMessageBox::Ok|QMessageBox::Cancel, QMessageBox::Cancel) == QMessageBox::Cancel) return; QFile::remove(fileName); }
file = new QFile(fileName); if (!file->open(QIODevice::WriteOnly)) { QMessageBox::information(this, tr("HTTP"), tr("Unable to save the file %1: %2.") .arg(fileName).arg(file->errorString())); delete file; file = 0; return; }
if (!url.userName().isEmpty()) http->setUser(url.userName(), url.password());
httpRequestAborted = false; QByteArray path = QUrl::toPercentEncoding(url.path(), "!$&'()*+,;=:@/"); if (path.isEmpty()) path = "/";
QHttpRequestHeader header("GET", url.path()); header.setValue("Host", url.host()); header.setValue("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7 (.NET CLR 3.5.30729)"); header.setValue("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); header.setValue("Accept-Language", "en-us,en;q=0.5"); //header.setValue("Accept-Encoding", "gzip,deflate"); header.setValue("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"); header.setValue("Keep-Alive", "300"); header.setValue("Proxy-Connection", "keep-alive");
//header.setValue("Connection", "keep-alive"); header.setValue("Cookie", "AspxAutoDetectCookieSupport=1; path=/"); QHttp::ConnectionMode mode = url.scheme().toLower() == "https" ? QHttp::ConnectionModeHttps : QHttp::ConnectionModeHttp; http->setHost(url.host(), mode, url.port() == -1 ? 0 : url.port()); if (ui->cbProxy->isChecked()) { QNetworkProxy proxy; proxy.setType(QNetworkProxy::HttpProxy); proxy.setHostName("192.100.201.145"); proxy.setPort(8080); http->setProxy(proxy); } ui->lineEdit2->setText(header.toString()); httpGetId = http->request(header, 0, file);
//httpGetId = http->get(path, file);
progressDialog->setWindowTitle(tr("HTTP")); progressDialog->setLabelText(tr("Downloading %1.").arg(fileName)); ui->loadLineButton->setEnabled(false); ui->statusLabel->setText(path + " " + fileName + " " + url.host()); }
|
При выполнении этого слота у меня выводится диалоговое окошко proxy dialog с запросом ISA на авторизацию. Ввожу туда данные моей учетной записи, как обычно, но ничего не происходит и вновь приходит запрос на авторизацию. Включаю сниффер, смотрю:  Теперь то же самое, но через браузер:  Из сравнения вытекает, что 1. В Qt вместо моего реального домена подставляется имя шлюза. 2. В браузере в поле HostName подставляется имя моей рабочей машины, а в Qt - NULL Подскажите пожалуйста что делать, а то гугл не помог ничем. P.S. Пример DemoBrowser из Qt тоже не работает Это сообщение отредактировал(а) aspirin2003 - 19.6.2009, 14:07
|