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........
Asked
Active
Viewed 416 times
1 Answers
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