Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: HttpClient - transferred data size

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HttpClient - transferred data size

    hi
    I would upload files to the server with this function.
    2 second intervals, How do I print the transferred data size ?
    public void PostFile()  {
        try {
            HttpClient httpclient = new DefaultHttpClient();
            httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
            File file = new File("D:/data.zip");
            HttpPost httppost = new HttpPost("upload.php");  
            HttpEntity httpEntity = MultipartEntityBuilder.create()
                .addBinaryBody("userfile", file, ContentType.create("application/zip"), file.getName())
                .build();
     
            httppost.setEntity(httpEntity);
     
            System.out.println("executing request " + httppost.getRequestLine());
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity resEntity = response.getEntity();    
            System.out.println(response.getStatusLine()); 
            if (resEntity != null) {
                System.out.println(EntityUtils.toString(resEntity));
            }
            if (resEntity != null) {
                resEntity.consumeContent();
            }
     
            httpclient.getConnectionManager().shutdown();
        } catch (Exception e) {
            System.out.println("hata: "+e);
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: HttpClient - transferred data size

    Get the file's size from the File object. Use the println() method to print it.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: HttpClient - transferred data size

    I guess you did not understand. -sorry for bad english.
    Using Thread.Sleep, two second intervals want to print the size of the data sent. ok ?

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: HttpClient - transferred data size

    I don't know where that information is available. What packages are you using to send the data? Are there any methods that give the number of bytes that have been sent?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Jpanel preffered size exceed the nactual screen size
    By manish.ctae@gmail.com in forum AWT / Java Swing
    Replies: 2
    Last Post: October 31st, 2012, 01:29 AM
  2. [Asking] httpclient with ssl
    By ardisamudra in forum Java Networking
    Replies: 0
    Last Post: October 30th, 2012, 06:58 AM
  3. Replies: 1
    Last Post: March 31st, 2012, 06:52 PM
  4. Replies: 0
    Last Post: April 30th, 2011, 10:02 AM
  5. tutorial for proxyauthentication using httpclient
    By jaya in forum Java Networking
    Replies: 1
    Last Post: January 21st, 2011, 09:28 AM