Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3353896
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:12:24+00:00 2026-05-18T02:12:24+00:00

This is the first http programming i’ve done and I’m self-taught so this may

  • 0

This is the first http programming i’ve done and I’m self-taught so this may be a stupid question…

edit:Ultimately my question boils down to: What’s a good way to get access to all of the contents of an HttpResponse (i.e. headers + entity) but in my own sweet time? i.e. Download and then let the client process.

I’ve made a method which places an http GET request to a server. That all works fine, and I use the HttpClient.execute() function to send it off and it returns an HttpResponse object with my XML content in the entity body. My concern is that the official Apache tutorial cites the importance of ‘consuming’ the response entity content in order to free up the connection used to communicate the response. Why wouldn’t it be free? Does this mean that after execute has returned the HttpResponse but before I have done anything with it, that the client hasn’t actually received the entity body, and that only when I explicitly access the input stream that comes from it that my client actually receives the body, on some connection that has been waiting around for me to ask?

I have been using BufferedHttpEntity objects to immediately buffer the response entity to make sure that there are no timeout issues from my client not handling the response quickly enough but i’m not sure if this is necessary. When SHOULD I be using a BufferedHttpEntity?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:12:25+00:00Added an answer on May 18, 2026 at 2:12 am

    You need to consume the whole data yourself. BufferedHttpEntry just bufferes a proportion of the data of the stream. If you do not want the data you can use the consumeContent() method to ignore the rest of the input.

    If you do not consume the whole data the server connection will be opened in the background. The server wants to give you the data but you ignore it leaving a stream open on the server end.. Eventually the server will time out.

    Maybe you do not consume all the content when getting your XML. Maybe a character is left on the server end. By calling consumeContent() you free up this last byte.

    This example consumes all the content (reading the stream till it ends):

    public class HttpTest {
        public static void main(String... args) throws Exception {
    
            System.out.println(readTextPage(new URL("http://stackoverflow.com")));
        }
    
        private static String readTextPage(URL url) throws Exception {
    
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet(url.toURI());
            HttpResponse response = client.execute(request);
    
    
            Reader reader = null;
            try {
                reader = new InputStreamReader(response.getEntity().getContent());
    
                StringBuffer sb = new StringBuffer();
                {
                    int read;
                    char[] cbuf = new char[1024];
                    while ((read = reader.read(cbuf)) != -1)
                        sb.append(cbuf, 0, read);
                }
    
                return sb.toString();
    
            } finally {
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is beyond both making sense and my control. That being said here is
I have found this example on StackOverflow: var people = new List<Person> { new
I want to use a temp directory that will be unique to this build.
I'm trying to build a C++ extension for python using swig. I've followed the
I was reading JavaScript: The Good Parts and the author mentions that JavaScript is
Let say I have the following desire, to simplify the IConvertible's to allow me
I am attempting to pull some information from my tnsnames file using regex. I
After having read Ian Boyd 's constructor series questions ( 1 , 2 ,
I am using a 3rd-party rotator object, which is providing a smooth, random rotation
I have a new web app that is packaged as a WAR as part

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.