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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:36:53+00:00 2026-06-02T22:36:53+00:00

I want to make a simple HTTPRequest to a php script and I have

  • 0

I want to make a simple HTTPRequest to a php script and I have tried to make the very most basic of apps to get the functionality working. I want to test that my app is sending the data I feed it so I’ve made the android app send to a server and that server is supposed to send me the data I’ve put into the app. The code for the “postData” function is to send data from android to the server and the code for the “default.php” is the recieving php file on a webserver which then forwards the data to my email address (not given). Here is the code

    public void postData() {

    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://somewhere.net/default.php");

    try {
        // Add your data
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("thename", "Steve"));
        nameValuePairs.add(new BasicNameValuePair("theage", "24"));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        //HttpResponse response = httpclient.execute(httppost);

        // Execute HTTP Post Request
        ResponseHandler<String> responseHandler=new BasicResponseHandler();
        String responseBody = httpclient.execute(httppost, responseHandler);

    //Just display the response back
    displayToastMessage(responseBody);

    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
    } catch (IOException e) {
        // TODO Auto-generated catch block
    }
}

as well as for “default.php”

<?php 
$thename=$_GET["thename"]; 
$theage=$_GET["theage"];

$to = "someemail@gmail.com";
$subject = "Android";
$body = "Hi,\n\nHow are you," . $thename . "?\n\nAt " . $theage . " you are getting old.";
if (mail($to, $subject, $body)) 
{
echo("<p>Message successfully sent!</p>");
} 
else 
{
echo("<p>Message delivery failed...</p>");
}
?>

Here are the links to the code in pastebin:
postData() and default.php

I recieve an email however the data sent “thename” and “theage” seem to be empty. The exact email received is
“Hi,
How are you,?
At you are getting old.”
which indicates to me that the server is sending thename and theage as empty. Have any of you tried this before? What am I doing incorrectly?
Thank you so much for taking the time out to read my code and if possible to reply to my questions.

EDIT: Very idiotic of me -> the “GETS” need to change to “POST”. Leaving it here for archive purposes 🙂

  • 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-02T22:36:57+00:00Added an answer on June 2, 2026 at 10:36 pm

    You’re using $_GET instead of $_POST to get the values of the posted data. You want

    <?php 
    $thename=$_POST["thename"]; 
    $theage=$_POST["theage"];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a simple news system using PHP and MySQL, right now
I want to make a simple script to post a tweet from a Textbox
i want to make a simple jquery slider, i dont know jquery very well,
Basically I want to make simple toggle program (that will be mapped to some
I need information about making installation packages for Linux. I want to make simple
I want to make a simple app, where a UIWebView with custom content will
I want to make a simple game: 2d, single-player, without tons of animations and
I want to make a simple game so that I can play against my
I want to make a simple program that sends random keystrokes to my other
I want to make a simple phylogenetic tree for a marine biology course as

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.