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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:29:21+00:00 2026-05-25T09:29:21+00:00

I am trying to make my application post something to my webserver (located at

  • 0

I am trying to make my application post something to my webserver (located at IP 10.0.2.2) and receive the response. I’m using a HttpHelper object to do all the server-interaction methods. At the moment my response variable is not getting anything back. Through debugging I know that the loop:

while ((line = rd.readLine()) != null) {

is never entered, but it should be entered because it should receive the line ‘OK’ surely?

Thanks very much for your help!

The webpage code is just:

header("HTTP/1.1 200 OK");

The java code is:

        List<NameValuePair> data = new ArrayList<NameValuePair>();
        HttpHelper httpHelper = new HttpHelper("http://10.0.2.2/", data);
        StringBuilder response = httpHelper.postData();

…

public class HttpHelper {
final HttpClient client;
final HttpPost post;
final List<NameValuePair> data;

public HttpHelper(String address, List<NameValuePair> data) {
    client = new DefaultHttpClient();
    post = new HttpPost(address);
    this.data = data;
}

private class GetResponseTask extends AsyncTask<Void, Void, StringBuilder> {
    protected StringBuilder doInBackground(Void... arg0) {
        try {
            HttpResponse response = client.execute(post);
            return inputStreamToString(response.getEntity().getContent());
        } catch (ClientProtocolException e) {
            Log.e("debug", e.getLocalizedMessage());
        } catch (IOException e) {
            Log.e("debug", e.getLocalizedMessage());
        }
        return null;
    }
}

public StringBuilder postData() {
    try {
        post.setEntity(new UrlEncodedFormEntity(data));
        return (new GetResponseTask().execute()).get();
    } catch (UnsupportedEncodingException e) {
        Log.e("debug", e.getLocalizedMessage());
    } catch (InterruptedException e) {
        Log.e("debug", e.getLocalizedMessage());
    } catch (ExecutionException e) {
        Log.e("debug", e.getLocalizedMessage());
    }
    return null;
}

private StringBuilder inputStreamToString(InputStream is)
        throws IOException {
    String line = "";
    StringBuilder total = new StringBuilder();

    // Wrap a BufferedReader around the InputStream
    BufferedReader rd = new BufferedReader(new InputStreamReader(is));

    // Read response until the end
    while ((line = rd.readLine()) != null) {
        Log.v("debug", "top of readlineloop");
        total.append(line);
        Log.v("debug-readline", line);
    }
    // Return full string
    return total;
}
}
  • 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-25T09:29:22+00:00Added an answer on May 25, 2026 at 9:29 am

    The response entity, the one returned by getEntity(), does not include the response headers, and it looks like that’s what you’re interested in. To retrieve the status code, use:

    response.getStatusLine().getStatusCode()
    

    The “entity” is reponse content.

    EDIT: to emit content from PHP, use echo, print_r(), var_dump(), numerous other functions, and – most importantly – all text outside of <?php...?> tags.

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

Sidebar

Related Questions

I'm trying to make an application that keeps an object model in sync with
I'm trying to make a post request via ajax using jQuery (for the BaseCamp
I am trying to make a desktop application in python to post messages to
I am trying to make an application which is able to post images on
Good day. I'm trying to make an online quiz application using php. The idea
I'm trying to make an application in which both the developer and the end
I am trying to make an application for drawing shapes on screen by touching
Alright so here is the deal. I am trying to make a application that's
Recently I was trying to make a calendar application that will display the current
I'm currently trying to make a small application that performs different duties. Right now

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.