-1

I am trying to communicate between my web and android, I have difficulty to send data from my android to php page, I am using JSON to communicate, How can I do this please Help me........

Sahi
  • 17
  • 2
  • 5
  • please go through the link following: http://stackoverflow.com/questions/3027066/how-to-send-a-json-object-over-request-with-android – Basil Aug 06 '11 at 10:07

1 Answers1

1

Why don't you instead actually do a POST-request from your device to the php-page? PHP is after all really good at handling requests, so it shouldn't really be a problem. Try this out:

Java:

// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://yoursite.com");

try {
    // Add your data
    List<BasicNameValuePair> nameValuePairs = new ArrayList<BasicNameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("string1", "foo"));
nameValuePairs.add(new BasicNameValuePair("string2", "bar"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

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

    //Check the response
    if( response == null ) return null;

    //POST DONE

} catch( Exception ex ) {

    ex.printStackTrace();

}

php:

<?php
    if( isset($_POST['string1']) ) {

        //Do stuff with the $_POST

    } else {

        //Nothing to see here

    }
?>
karllindmark
  • 6,031
  • 1
  • 26
  • 41