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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:22:48+00:00 2026-05-25T17:22:48+00:00

I am trying to get a Android device to send some information to a

  • 0

I am trying to get a Android device to send some information to a local host. I believe I have the Android sending the information, but my PHP code is not accepting or not displaying the code. I have attached my code, is there something I have missed? I am running wamp server also, and have put the permissions into the manifest.

Java Code: #

HttpPost httppost;

    HttpClient httpclient;

    // List with arameters and their values
    List<NameValuePair> nameValuePairs;

    String serverResponsePhrase;
    int serverStatusCode;
    String bytesSent;
    String serverURL = "http://10.0.2.2/test/index.php";


    httppost = new HttpPost(serverURL);
    httpclient = new DefaultHttpClient();
    nameValuePairs = new ArrayList<NameValuePair>(2);

    // Adding parameters to send to the HTTP server.
    nameValuePairs.add(new BasicNameValuePair("parameterName1", "git"));
    nameValuePairs.add(new BasicNameValuePair("parameterName2", "git"));

    // Send POST message with given parameters to the HTTP server.
    try {
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        HttpResponse response = httpclient.execute(httppost);

        InputStream is = response.getEntity().getContent();
        BufferedInputStream bis = new BufferedInputStream(is);
        ByteArrayBuffer baf = new ByteArrayBuffer(20);

        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }

        bytesSent = new String(baf.toByteArray());

        // Response from the server
        serverResponsePhrase = response.getStatusLine().getReasonPhrase();
        serverStatusCode = response.getStatusLine().getStatusCode();
        System.out.println("COMPLETE");
    } catch (Exception e) {
        // Exception handling
        System.out.println("Problem is " + e.toString());
    }

PHP Code:

<?php
echo "param1 value: ".$_POST['parameterName1']."\n";
echo "param2 value: ".$_POST['parameterName2']."\n";
?>

I also tried this code, but it did not work with my PHP

HttpPost httppost;

    HttpClient httpclient;

    // List with arameters and their values
    List<NameValuePair> nameValuePairs;

    String serverResponsePhrase;
    int serverStatusCode;
    String bytesSent;
    String serverURL = "http://10.0.2.2/test/index.php";


    httppost = new HttpPost(serverURL);
    httpclient = new DefaultHttpClient();
    nameValuePairs = new ArrayList<NameValuePair>(2);

    // Adding parameters to send to the HTTP server.
    nameValuePairs.add(new BasicNameValuePair("'parameterName1'", "git"));
    nameValuePairs.add(new BasicNameValuePair("'parameterName2'", "git"));

    // Send POST message with given parameters to the HTTP server.
    try {
        HttpEntity entity = new UrlEncodedFormEntity(nameValuePairs);

        httppost.addHeader(entity.getContentType());
        httppost.setEntity(entity);


        HttpResponse response = httpclient.execute(httppost);

        InputStream is = response.getEntity().getContent();
        BufferedInputStream bis = new BufferedInputStream(is);
        ByteArrayBuffer baf = new ByteArrayBuffer(20);

        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }

        bytesSent = new String(baf.toByteArray());

        // Response from the server
        serverResponsePhrase = response.getStatusLine().getReasonPhrase();
        serverStatusCode = response.getStatusLine().getStatusCode();
        System.out.println("response" + response.toString());
        System.out.println("COMPLETE");
    } catch (Exception e) {
        // Exception handling
        System.out.println("Problem is " + e.toString());
    }
  • 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-25T17:22:48+00:00Added an answer on May 25, 2026 at 5:22 pm

    Make sure the Content-Type HTTP header is getting set. Try replacing

    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    

    with this

    HttpEntity entity = new UrlEncodedFormEntity(nameValuePairs);
    
    httppost.addHeader(entity.getContentType());
    httppost.setEntity(entity);
    

    Also, instead of response.toString(), try EntityUtils.toString(response.getEntity()) if you want to see the body of the response

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

Sidebar

Related Questions

I am trying to get a trace of an Android device but I am
I'm trying to get from an Android Uri to a byte array. I have
I'm trying to make a notification in Android. But i get the error in
I have been trying to get the Fusion Charts to work on Android 2.2
Greetings, I'm trying to upload an image on my Android device. I have the
I'm trying to get a webstageview to load a local html file....this code works
I am trying to do a demo on a android device, but the screen
I'm currently trying to get a grip on Android development and working my way
I'm writing my first Android application and trying to get my head around communication
I'm battling with Android's awful layout system. I'm trying to get a table to

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.