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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:16:08+00:00 2026-06-09T14:16:08+00:00

I have been trying to get my Android App to post data to a

  • 0

I have been trying to get my Android App to post data to a PHP file, which then writes that data to a database, however I’m having a bit of trouble with it.

I’m getting this error, however it’s not force closing or anything.

Logcat Output:

08-13 20:29:42.859: I/postData(11950): HTTP/1.1 200 OK
08-13 20:29:42.859: E/log_tag(11950): Error in http connectionjava.lang.IllegalStateException: Content has been consumed

Here is the code in question that’s doing all my HTTP POST stuff, the android side of things:

SubmitWord task = new SubmitWord(); 
task.execute(new String[] { "http://www.hanged.comli.com/main.php" });

The above code calls this asynchronous task:

          private class SubmitWord extends AsyncTask<String, Void, String> 
    {
        @Override
        protected String doInBackground(String... urls) 
        {
          String response = "";
          try
          {
            URL = urls[0];
            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
            nameValuePairs.add(new BasicNameValuePair("victim",myId));
            nameValuePairs.add(new BasicNameValuePair("rival",newname));
            nameValuePairs.add(new BasicNameValuePair("word","HELLOHOMO"));
            nameValuePairs.add(new BasicNameValuePair("won","0"));

              HttpClient httpclient = new DefaultHttpClient();
              HttpPost httppost = new      
              HttpPost(URL);
              httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

              HttpResponse execute = httpclient.execute(httppost);
              HttpEntity entity = execute.getEntity();
              InputStream is = entity.getContent();

             Log.i("postData", execute.getStatusLine().toString());
             //HttpEntity entity = response.getEntity();
              is = entity.getContent();
          }
          catch(Exception e)
          {
                  Log.e("log_tag", "Error in http connection"+e.toString());
          }
                return response;
            } 

        @Override
        protected void onPostExecute(String result) 
        {
          mText.setText("DONE");
        }

      }

Here is the PHP side of things:

<?php

 /// REMOVED DATABASE DETAILS

$connect = mysql_connect("$mysql_host", "$mysql_user", "$mysql_password")or die("cannot   connect");
 mysql_select_db("$mysql_database", $connect)or die("cannot select DB");

session_start();

$victim = $_POST['victim'];
$rival = $_POST['rival'];
$word = $_POST['word'];
$won = $_POST['won'];

mysql_query("INSERT INTO currentgames (victim, rival, wordguess, won) VALUES('$victim',       '$rival', '$word', '$won'))");

I’m fairly sure it’s just the Java/Android part that I’ve gotten wrong, but I can’t figure out for the life of me what I’m doing wrong, I have tried various different methods of POSTING data and read a number of tutorials on using HTTPOST. Maybe I’m just not understanding correctly.

  • 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-09T14:16:10+00:00Added an answer on June 9, 2026 at 2:16 pm

    The culprit is you are calling getContent(); twice.

    As per javadoc

    Returns a content stream of the entity. Repeatable entities are expected to create a new instance of InputStream for each invocation of this method and therefore can be consumed multiple times. Entities that are not repeatable are expected to return the same InputStream instance and therefore may not be consumed more than once.

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

Sidebar

Related Questions

(post updated for working code) I've been trying to get my android app to
I have been trying to develop an Android app which lets the user take
I have been trying to get a USB HID keyboard working on an Android
I have been trying to get the FTDI D2xx driver working with my Android
I have been trying to get a custom Value from the Custom Field that
I am trying to create a simple 3-D app for android that will have
I have been trying to get this android service working but I can not
I've been learning android development and been trying to get the app on my
I've been learning android development and been trying to get the app on my
Good afternoon. I have been making a small openGL based app for android that

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.