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 6385561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:54:56+00:00 2026-05-25T02:54:56+00:00

I am currently trying to get HttpComponents to send HttpRequests and retrieve the Response.

  • 0

I am currently trying to get HttpComponents to send HttpRequests and retrieve the Response.
On most URLs this works without a problem, but when I try to get the URL of a phpBB Forum namely http://www.forum.animenokami.com the client takes more time and the responseEntity contains passages more than once resulting in a broken html file.

For example the meta tags are contained six times. Since many other URLs work I can’t figure out what I am doing wrong.
The Page is working correctly in known Browsers, so it is not a Problem on their side.

Here is the code I use to send and receive.

        URI uri1 = new URI("http://www.forum.animenokami.com");
    HttpGet get = new HttpGet(uri1);
    get.setHeader(new BasicHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:6.0) Gecko/20100101 Firefox/6.0"));
    HttpClient httpClient = new DefaultHttpClient();
    HttpResponse response = httpClient.execute(get);
    HttpEntity ent = response.getEntity();
    InputStream is = ent.getContent();
    BufferedInputStream bis = new BufferedInputStream(is);
    byte[] tmp = new byte[2048];
    int l;
    String ret = "";
    while ((l = bis.read(tmp)) != -1){
        ret += new String(tmp);
    }

I hope you can help me.
If you need anymore Information I will try to provide it as soon as possible.

  • 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-25T02:54:56+00:00Added an answer on May 25, 2026 at 2:54 am

    This code is completely broken:

    String ret = "";
    while ((l = bis.read(tmp)) != -1){
        ret += new String(tmp);
    }
    

    Three things:

    • This is converting the whole buffer into a string on each iteration, regardless of how much data has been read. (I suspect this is what’s actually going wrong in your case.)
    • It’s using the default platform encoding, which is almost never a good idea.
    • It’s using string concatenation in a loop, which leads to poor performance.

    Fortunately you can avoid all of this very easily using EntityUtils:

    String text = EntityUtils.toString(ent);
    

    That will use the appropriate character encoding specified in the response, if any, or ISO-8859-1 otherwise. (There’s another overload which allows you to specify which character encoding to use if it’s not specified.)

    It’s worth understanding what’s wrong with your original code though rather than just replacing it with the better code, so that you don’t make the same mistakes in other situations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently trying to get one of my unit tests to work, but there
I'm currently trying to get something to run involving trigonometry but I've run across
I am currently trying to get some statistics for my website but i cant
Maybe I have a bad design but I am currently trying to get an
I'm currently trying to get this image-map to work: <img src=products1.png usemap=products1-map style=margin-bottom: 36px
I'm currently trying to get a simple bundle containing a Service Factory running. This
I am currently trying to get OpenLayers to show a WMS-Layer. Doing this I
I'm currently trying to get an rdlc report to work, and it works fine
I'm currently trying to get the contents of an iframe's body without any mangling
I am currently trying to split one value with percentage column. But as most

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.