PDA

View Full Version : QHttp with localhost.



William Wilson
30th June 2007, 20:18
Qt version: 4.3.0
Platform: Win, Unix and Mac
Web server: IIS and Apache.
==================

Qhttp with localhost appears to have a bug in Qt 4.3.0. All the signals are emitted with no errors but the content is not retrieved in temp.txt using this simple code snippet.

QUrl url("http://localhost/temp/index.htm");
http = new QHttp(this);
http->setHost(url.host(), QHttp::ConnectionModeHttp);
file = new QFile("c:/temp/temp.txt");
if (!file->open(QIODevice::Truncate|QIODevice::WriteOnly)) {
delete file;
file = 0;
return;
}
int httpGetId = http->get(url.path(), file);

Even the responseHeaderReceived() signal is received correctly with something like this -

"Response headerHTTP/1.1 200 OK
server: Microsoft-IIS/5.1
x-powered-by: ASP.NET"

The browser is able to display this http://localhost/temp/index.htm

If I replace localhost URL with any other URL, it works fine.
When I searched through the archives and found a similar issue for QHttp with localhost with an older version of Qt.
http://lists.trolltech.com/qt-interest/2006-08/thread01082-0.html

Is there a work around in QHttp for localhost requests? Please help
Thanks for your help.

marcel
30th June 2007, 20:47
Do you handle the readyRead signal?
Also, try adding the port to the URL:


QUrl url("http://localhost:8080/temp/index.htm");



Regards

William Wilson
30th June 2007, 21:23
Thanks for the quick reply.

Tried with int httpGetId = http->get(url.path());
and handling the readyRead() signal and it worked!!!

Tried with http://localhost:8080/temp/index.htm but even that didn't work if I provide an IODevice* to the get() call
The doc says readyRead signal is not emitted if you provide an IODevice* to the get() call since the content will get written to the pointer you provided during the get() call:
int httpGetId = http->get(url.path(), file);
The strange thing is it is working fine if the URL is on the www. For example, QUrl url("http://trolltech.com/developer");

So, the work around is, as you suggested handling the readyRead() signal and not providing an IODevice*.

Thanks a lot for your help.

marcel
30th June 2007, 21:26
The strange thing is it is working fine if the URL is on the www. For example, QUrl url("http://trolltech.com/developer");
Oh, OK then.

Regards