Downloading files using HttpConnection is very slow

Hi

I've written a program which will download files over HTTP protocol using the class HttpConnection. I am connecting to the net using Proxy with authorization. At times it takes long time to download even a 2 MB file, but it works very fast on fewer occasions. The same file If I try to download using browser such as IE or FireFox, download happens in few seconds.

I am not sure where the problem is. Can anyone guide me on this issue?

Regards,

Faisal

[486 byte] By [ebrahim.faisala] at [2007-10-3 2:51:30]
# 1
maybe you can post your code up here for people to see and diagonise the problem.
I_was_caspar50708a at 2007-7-14 20:40:23 > top of Java-index,Core,Core APIs...
# 2

If you are erforming downloads of multiple files then use Apache HTTP client which is faster.

The HTTPUrlConnection do not seem to utilize the Connection Keep Alive feature of HTTP so it create a seperate connection for each request.

By the way there might be problems in your code too post it here so we can look in to it.

LRMKa at 2007-7-14 20:40:23 > top of Java-index,Core,Core APIs...
# 3
> The HTTPUrlConnection do not seem to utilize the> Connection Keep Alive feature of HTTP so it create a> seperate connection for each request.Eh? The Sun implementation can utilize HTTP Connection Keep Alive if you tell it to, and it also runs a connection
ejpa at 2007-7-14 20:40:23 > top of Java-index,Core,Core APIs...
# 4

> > The HTTPUrlConnection do not seem to utilize the

> > Connection Keep Alive feature of HTTP so it create

> a

> > seperate connection for each request.

>

> Eh? The Sun implementation can utilize HTTP

> Connection Keep Alive if you tell it to, and it also

> runs a connection pool.

Great! can you explain a bit how you enable it?

Can I just do it by setting the Connection: Keep-Alive header

LRMKa at 2007-7-14 20:40:23 > top of Java-index,Core,Core APIs...
# 5
Just don't set -Dhttp.keepAlive=false, then it will respect the header Connection: keep-alive. Idle pooled connections time out eventually depending on the message headers, presence/abence of content-length, etc etc.All this is in sun.net.www.http.HttpClient.
ejpa at 2007-7-14 20:40:23 > top of Java-index,Core,Core APIs...