Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, December 2006
QHttp - problem downloading file


Message 1 in thread

Hi, 

I am trying to download the following file from the internet using the QHttp get function-

http://ichart.finance.yahoo.com/table.csv?s=DVAX&d=11&e=14&f=2006&g=d&a=3&b=7&c=1992&ignore=.csv

This is a csv file showing showing some stock data.

I use the following 2 lines to do this -

http->setHost(httpUrl.host(), httpUrl.port(80));
httpGetId = http->get(httpUrl.path(), file);


where
http: QHttp instance;
httpUrl : QUrl - set to the above URL

I am successful in downloading html files using the same code, but when I try and download the above file it seems to download some html content and not the file content.

Thanks in advance,
R



 
---------------------------------
Have a burning question? Go to Yahoo! Answers and get answers from real people who know.

Message 2 in thread

On Thu, 14 Dec 2006 16:18:31 -0800 (PST)
roger t <roger90902003@xxxxxxxxx> wrote:

> I am successful in downloading html files using the same code, but
> when I try and download the above file it seems to download some html
> content and not the file content.

First, check what the html content is -- maybe an error message page.
Second, check the response code of the request -- it should be 200
when successful, orher (not a 2xx code but 3xx, 4xx or 5xx) when an
error occurs.

--
 [ signature omitted ] 

Message 3 in thread

Hi,

> http: QHttp instance;
> httpUrl : QUrl - set to the above URL

How is it set?

> I am successful in downloading html files using the same code, but when 
> I try and download the above file it seems to download some html content 
> and not the file content.

How do you see that?

--
 [ signature omitted ] 

Message 4 in thread

Hi Dimitri,

Here is the code I use to set the URL and get the file:
---------------------------------------------------------
QUrl httpUrl;       
httpUrl.setUrl("http://ichart.finance.yahoo.com/table.csv?s=DVAX&d=11&e=14&f=2006&g=d&a=3&b=7&c=1992&ignore=.csv";);
QFileInfo fileInfo(httpUrl.path());
QString fileName = fileInfo.fileName();

QFile* file = new QFile(fileName);
if (!file->open(QIODevice::WriteOnly))
 {
        return;
 }
    
http->setHost(httpUrl.host(), httpUrl.port(80));
httpGetId = http->get(httpUrl.path(), file);
------------------------------------------------------------------------------
comment:
//http: QHttp instance, which i create in my constructor

On using the above URL I am able to write the file "table.csv" (this is the file I am trying to download) to disk but the content seems wrong. If you copy paste the above URL in your browser and open the file , you will see the correct file content . Also the correct file is a much larger file. Right now I get some small file "table.csv" with html code in it.

Hope this helps.

Roger

Dimitri <dimitri@xxxxxxxxxxxxx> wrote: Hi,

> http: QHttp instance;
> httpUrl : QUrl - set to the above URL

How is it set?

> I am successful in downloading html files using the same code, but when 
> I try and download the above file it seems to download some html content 
> and not the file content.

How do you see that?

--
 [ signature omitted ] 
Message 5 in thread

Hi,

> [...] Right now I get some small file "table.csv" with html code 
> in it.

What does this HTML code look like?

--
 [ signature omitted ] 

Message 6 in thread

On Mon, 2006-12-18 at 14:06 -0800, roger t wrote:

> QUrl httpUrl;       
> httpUrl.setUrl("http://ichart.finance.yahoo.com/table.csv?s=DVAX&d=11&e=14&f=2006&g=d&a=3&b=7&c=1992&ignore=.csv";);
> QFileInfo fileInfo(httpUrl.path());
> QString fileName = fileInfo.fileName();
> 
> QFile* file = new QFile(fileName);
> if (!file->open(QIODevice::WriteOnly))
>  {
>         return;
>  }
>     
> http->setHost(httpUrl.host(), httpUrl.port(80));
> httpGetId = http->get(httpUrl.path(), file);
> ------------------------------------------------------------------------------

The Url contains a query string. You are not passing this to
http->get(). You are merely passing the path ("/table.csv").

http://doc.trolltech.com/4.2/qurl.html#setPath

Perhaps you want

  httpGetId = http->get(httpUrl.toEncoded(), file);

Hope this helps,

Stephen Jackson



--
 [ signature omitted ] 

Message 7 in thread

Hi,

> httpGetId = http->get(httpUrl.path(), file);

 From the QHttp:get() documentation:
	http://doc.trolltech.com/4.2/qhttp.html#get
	The function does not block and returns immediately. The
	request is scheduled, and its execution is performed
	asynchronously. The function returns a unique identifier
	which is passed by requestStarted() and requestFinished().
	When the request is started the requestStarted() signal
	is emitted. When it is finished the requestFinished()
	signal is emitted.
Is there an event loop running in your application?

--
 [ signature omitted ]