Hi,
We have an application that downloads small text files (< 2 Kb) from a webserver. These files are downloaded 1 by 1 when needed. We open a HttpURLConnection, download 1 file and close the connection immediately afterwards. This is done for each file and hence produces a significant overhead.
For performance reasons (both client and server side), we would like to open a connection to the webserver once, download a number of files and then close the connection.
Currently, our code roughly looks like:
InputStream is;
HttpURLConnection con;
int resp;
try {
URL url = new URL(location);
con = (HttpURLConnection)url.openConnection();
resp=con.getResponseCode();
if(resp==HttpURLConnection.HTTP_OK) {
is = con.getInputStream();
// ... read data from the InputStream
is.close();
}
} catch (MalformedURLException murle) {
murle.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
}
Is it even possible to download multiple files from a web server using a HttpURLConnection? If so, how? :-)
Please note that the solution should be compliant with J2SE 1.1, since we are writing an MHP application!
Thanks in advance...