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

  • SEARCH
  • Home
  • 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 9135765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:51:57+00:00 2026-06-17T08:51:57+00:00

Edit: hello has been deleted. So, hello. By reaching an URL, I should get

  • 0

Edit: “hello” has been deleted. So, hello.

By reaching an URL, I should get a string as response. So I borrowed a part of code on this website and adapted in a method to get my string into a variable. Unfortunatelly, the “Try” block is skipped and the returned string is “*“. What do I have misunderstood something about this script ?

Is the variable “response” what I should get as a response, or something else ?

Thanks in advance.

    private String getMessages() {
    String response = "***";
    try {
        HttpClient client = new DefaultHttpClient();  
        String getURL = "http://***.com/message/";
        HttpGet get = new HttpGet(getURL);
        HttpResponse responseGet = client.execute(get);  
        HttpEntity resEntityGet = responseGet.getEntity();  
        if (resEntityGet != null) {  
            // do something with the response
            response = EntityUtils.toString(resEntityGet);
            Log.i("GET RESPONSE", response);
        }
    } catch (Exception e) {
        e.printStackTrace();

    }

    return response;
}
  • 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-06-17T08:51:58+00:00Added an answer on June 17, 2026 at 8:51 am

    I don’t know if this works correctly but this is the basic idea what you must do

    StringBuilder builder = new StringBuilder();
    InputStream content = entity.getContent();
                        BufferedReader reader = new BufferedReader(new InputStreamReader(content));
                        String line;
                        while ((line = reader.readLine()) != null) {
                            builder.append(line);
                        }
    String response = builder.toString();
    

    UPDATE:

    This is a short snipped of my code, which is working without problems:

    int statusCode = mResponse.getStatusLine().getStatusCode();
                        InputStream is = null;
                        StringBuilder stringBuilder = new StringBuilder();
                        if (statusCode == HttpStatus.SC_OK) {
                            HttpEntity entity = mResponse.getEntity();
                            if (entity != null) {
                                try {
                                    is = entity.getContent();
                                } catch (IllegalStateException e) {
                                    e.printStackTrace();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                byte[] buffer = new byte[1024];
                                int length;
                                try {
                                    while ((length = is.read(buffer)) > 0) {
                                        stringBuilder.append(new String(buffer, 0, length));
                                    }
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
    

    by the way the buffered reading is the best solution you can choose, but I dont really think thats your problem, as I have noticed before the HTTPEntity must not be null, so I assume there is something wrong with the HTTPRequest, maybe try to check the request-results using fiddler.

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

Sidebar

Related Questions

Edit: This has since been solved. Thanks to everyone who helped. Invoking the method
Hello I have a view that deletes order numbers. Once a string has been
Not sure if this has been answered before - how can I grab string
Hello all I have this problem that I can't seem to fix. I've been
G'day, This has been asked before for VC++ but I am interested in the
SOLVED see Edit 2 Hello, I've been writing a Perl program to handle automatic
Edit: Updating post based on Martins comments below Hello, I'm just trying to get
Okay i know this has been asked a lot but it seems that none
Hello I have an edit item form. From this view, look at item.current_item_status_date .
Hello I want a button to hide until my last image view has been

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.