Re:URLConnection help...

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re:URLConnection help...

Martin Lafaix

> From: [hidden email]
> In oppening a connect to a url, why is it that sometimes getContentLength will
> return -1 instead of the desired size of the URL? I'm accessing html and trying
> to implement a status bar to show the progress of the downloaded url. However,
> not knowing the target size makes it a bit difficult to calculate the progress.

URLConnection.getContentLength() will return -1 if the document's
header contains no Content-Length header field.  You can get this
if the server does not know the document's length (either because
the server is stupid or because this is a document generated in
realtime, for example).

Martin
--
[hidden email]
Team OS/2
http://www.multimania.com/lafaix

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to
[hidden email]
with the following message in the body of the note
unsubscribe ibm-netrexx <e-mail address>

Reply | Threaded
Open this post in threaded view
|

Re: URLConnection help...

mcbrides
>
>> From: [hidden email]
>> In oppening a connect to a url, why is it that sometimes getContentLength will
>> return -1 instead of the desired size of the URL? I'm accessing html and trying
>> to implement a status bar to show the progress of the downloaded url. However,
>> not knowing the target size makes it a bit difficult to calculate the progress.
>
>URLConnection.getContentLength() will return -1 if the document's
>header contains no Content-Length header field.  You can get this
>if the server does not know the document's length (either because
>the server is stupid or because this is a document generated in
>realtime, for example).
>

Hi Martin,

I appreciate that post, it probably explains the "wierd" data that I've been
getting back from some servers. In testing on my own webpage (no content-length
header field), it will return the correct byte count, smart server I guess.



--

/--------------------\
| Jerry McBride      |
| [hidden email] |
\--------------------/

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To unsubscribe from this mailing list ( ibm-netrexx ), please send a note to
[hidden email]
with the following message in the body of the note
unsubscribe ibm-netrexx <e-mail address>