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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:46:20+00:00 2026-06-09T18:46:20+00:00

So as the title suggest my problem is getting a response to a HTTP

  • 0

So as the title suggest my problem is getting a response to a HTTP POST I’m making.
What SHOULD be happening is I send a bunch of variables, the PHP checks the database for them and sends back to me the result (as an echo to the page).

Here is the android code:

 public class CheckChallenge 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",NetPlay.myId)); 
   // need to return these to an array
   nameValuePairs.add(new BasicNameValuePair("rival",rivalid));


        nameValuePairs.add(new BasicNameValuePair("word","null"));
        nameValuePairs.add(new BasicNameValuePair("won","0"));

          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new      
          HttpPost("http://www.hanged.comli.com/check-rival.php");
          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

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

          //InputStream is = entity.getContent();

          //mText.setText(is.toString());

         Log.i("postData", execute.getStatusLine().toString());
         //HttpEntity entity = response.getEntity();

      }
      catch(Exception e)
      {
              Log.e("log_tag", "Error in http connection"+e.toString());
      }
            return response;
        } 

    @Override
    protected void onPostExecute(String result) 
    {
        // CHECK ENTIRE DATABASE FOR MY ID //
        // IF MY ID IS THERE THEN THAT MEANS IVE CHALLENGED SOMEONE //


    }

  }

Here is the PHP which I think is ok just including this for completeness:
$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'];

$query = "SELECT rival FROM currentgames";
$result = mysql_query($query);

 if (!$result) 
 {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}

if (mysql_num_rows($result) == 0) 
{
echo "No rows found, nothing to print so am exiting";
exit;
}

 while ($row = mysql_fetch_assoc($result)) 
{
 echo $row["rival"];
}

Any help with this would be very appreciated, trying to get my head around all this HTTP POSTing stuff.

  • 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-09T18:46:22+00:00Added an answer on June 9, 2026 at 6:46 pm

    Example of sending an HTTP request and reading back the HTTP response:

    String res = "";
    String url = "http://www.domain.com/youscript.php";
    URL urlObj = new URL(url);
    URLConnection lu = urlObj.openConnection();
    
    
    // Send data - if you don't need to send data 
    // ignore this section and just move on to the next one
    String data = URLEncoder.encode("yourdata", "UTF-8");
    lu.setDoOutput(true);
    OutputStreamWriter wr = new OutputStreamWriter(lu.getOutputStream());
    wr.write(data);
    wr.flush();
    
    // Get the response
    BufferedReader rd = new BufferedReader(new InputStreamReader(lu.getInputStream()));
    String line = "", res = "";
    while ((line = rd.readLine()) != null) {
      res += line;
    }
    
    wr.flush();
    wr.close();
    System.out.println(res);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title suggest my problem is that some SharedPreferences I'm using are conflicting
As the title suggest, I would like to do the above. Example below: library(stringr)
As the title suggest, I've enabled right clicks for my tableview with customized rows.
Please suggest or change some suitlable title for this question as i am not
As the title may suggest, I have been using jQuery AJAX to try and
As the title suggest, for example, in 85% of the situation, I'd like to
Edit1 I am not sure if the title is best for the problem so
I am getting problem in alignment of element that is in FooterTemplate of GridView.
the title might suggest it, but i'm looking for a way to have Facebooks
Before you stop reading and suggest HTML Agility (based on the title), I am

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.