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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:24:35+00:00 2026-05-24T11:24:35+00:00

I changed nothing in this method but suddenly it takes very long. The code

  • 0

I changed nothing in this method but suddenly it takes very long. The code example below produces this error.

EDIT: i extracted the method in a single java application and tried to load the file and i have the same timeout. The 3 or 4. time he goes through this loop HttpMethodBase:691 he stops for 500 seconds at my local pc and the thread is sleeping. After sleeping the next line is outstream.close();

while ((len = instream.read(buffer)) > 0) {
   outstream.write(buffer, 0, len);
}

EDIT: Here is the example code if you wanna try it at home 🙂 (httpClient 3.1)

import java.io.IOException;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.methods.GetMethod;


public class TestLoadImage {

    /**
     * @param args
     */
    public static void main(String[] args) {
        byte[] image = loadPhotoFromUrl("https://fbcdn-sphotos-a.akamaihd.net/photos-ak-snc1/v2635/232/115/68310606562/n68310606562_2255479_948765.jpg");
        System.out.println(image.length);
    }

    private static class GetMethodIgnoringContentLength extends GetMethod {

        public GetMethodIgnoringContentLength(String uri) {
            super(uri);
        }

        @Override
        public long getResponseContentLength() {
            // ignores content-length header, fakes "not specified":
            return -1;
        }

    }
    public static byte[] loadPhotoFromUrl(String photoUrl) {
        HttpClient httpClient = new HttpClient();
        httpClient.getParams().setBooleanParameter("http.connection.stalecheck", true);
        GetMethod get = new GetMethodIgnoringContentLength(photoUrl);

        try {
            int httpStatus = httpClient.executeMethod(get);
            if (httpStatus == HttpStatus.SC_OK) {
                byte[] imageBytes = get.getResponseBody();
                if (imageBytes.length > 0) {
                    return imageBytes;
                } else {
                    System.out.println("Failed: empty response/zero data");
                }
            } else {
                System.out.println("Failed: "+ httpStatus);
            }
        } catch (IOException ioe) {
            System.out.println( ioe);
        } finally {
            get.releaseConnection();
        }

        return null;
    }
}
  • 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-24T11:24:36+00:00Added an answer on May 24, 2026 at 11:24 am

    Fixed it with an update to HttpClient4.1 (and some refactoring required therefor). But if someone knows the reason in the example above i switch the correct answer.

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

Sidebar

Related Questions

I'm using this method to copy a file: [fileManager copyItemAtPath:sourcePath toPath:targetPath error:&error]; I want
I changed the folder that my WordPress installation was in. However, this worked fine,
I have changed the Treeview.HideSelection = false; But how do I insure that when
This is not the first time I'm using this method to send a POST
This must be a misunderstanding from my side, but I have the following: I
Hi I'm trying to reach this goal but as far as I am, I've
I've used NSNotifications before but this is the first time I've tried to use
I have changes the code but the issue is still there CandidateResumeInfo candidateResumeInfo =
Basically, in the method below, for reasons unknown to myself or my team, the
I ran into a very vague error while doing some simple jQuery DOM manipulation.

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.