Http Compress Request

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 123456prakash
    New Member
    • Jan 2007
    • 35

    #1

    Http Compress Request

    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.1 65";
    SSLSocket serSoc = new SSLSocket(hostN ame,portNumber) ;
    serSoc.setNeedC lientAuth(false );

    System.out.prin tln("Connection "+serSoc.isConn ected());

    String fileURL = "/abc/"+fileName;
    OutputStream out = serSoc.getOutpu tStream();
    String msg = "GET " + fileURL + " HTTP/1.0\r\n\r\n" ;
    byte b[];
    try {
    b = msg.getBytes("A SCII7");
    }
    catch (UnsupportedEnc odingException ignored) {
    b = msg.getBytes();
    }
    out.write(b);
    out.flush();

    BufferedInputSt ream bin = new BufferedInputSt ream
    (serSoc.getInpu tStream());
    ByteArrayOutput Stream byteStream = new ByteArrayOutput Stream();
    int ch = 0;
    while ((ch = bin.read()) != -1) {

    byteStream.writ e(ch);
    }
    byte[] dataBytes = byteStream.toBy teArray();
    bin.close();
    byteStream.clos e();

    // Saving into the file
    String outFile = "C:\\" + fileName;
    FileOutputStrea m fileOut = new FileOutputStrea m(outFile);
    fileOut.write(d ataBytes);
    fileOut.flush() ;
    fileOut.close() ;
    System.out.prin tln("File Saved Sucessfully.... .:"+ fileName);

    } catch (IOException e) {
    System.err.prin tln(e);
    e.printStackTra ce();
    }
    catch (MalformedURLEx ception e) {
    System.err.prin tln(e);
    e.printStackTra ce();
    }
    }



    *************** *************** ***********
    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
Working...