By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,782 Members | 1,154 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,782 IT Pros & Developers. It's quick & easy.

Http Compress Request

P: 35
hi ,
I have a doubt .
I have a 5mb file on a server . I am downloading the file from my java application
My application is NOT a web aplication I am using https connection to the sever

My code is something like this

public static void downloadFileSSL(String fileName) {

String urlPath = "https://200.216.221.25/";
int portNumber = 443;
try {
String hostName = "172.16.1.165";
SSLSocket serSoc = new SSLSocket(hostName,portNumber);
serSoc.setNeedClientAuth(false);

System.out.println("Connection "+serSoc.isConnected());

String fileURL = "/abc/"+fileName;
OutputStream out = serSoc.getOutputStream();
String msg = "GET " + fileURL + " HTTP/1.0\r\n\r\n" ;
byte b[];
try {
b = msg.getBytes("ASCII7");
}
catch (UnsupportedEncodingException ignored) {
b = msg.getBytes();
}
out.write(b);
out.flush();

BufferedInputStream bin = new BufferedInputStream
(serSoc.getInputStream());
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
int ch = 0;
while ((ch = bin.read()) != -1) {

byteStream.write(ch);
}
byte[] dataBytes = byteStream.toByteArray();
bin.close();
byteStream.close();

// Saving into the file
String outFile = "C:\\" + fileName;
FileOutputStream fileOut = new FileOutputStream(outFile);
fileOut.write(dataBytes);
fileOut.flush();
fileOut.close();
System.out.println("File Saved Sucessfully.....:"+ fileName);

} catch (IOException e) {
System.err.println(e);
e.printStackTrace();
}
catch (MalformedURLException e) {
System.err.println(e);
e.printStackTrace();
}
}



*****************************************
This code is working fine but to download that file it take lot of time.
I came to know that we can do https compressed request of that file if that
sever supports that. My server supports that .
So how to make such type of compressed request . what type of parameters
I have to pass with the http header...

Or else if u have any other suggestion please give it
Jan 18 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.