Reputation: 815
I am trying to send data through post method in android . But how I can receive data in server. My server is in php. I found a method in php $_post[]. how can i use it? my client code is
client=new DefaultHttpClient();
HttpPost request=new HttpPost("http://10.0.2.2/php_server/index.php");
HttpEntity entity;
try
{
StringEntity string=new StringEntity("I am android");
entity=string;
request.setEntity(entity);
HttpResponse response=client.execute(request);
}
catch(Exception e)
{
Log.e("socket connection", e.toString());
}
Upvotes: 2
Views: 1270
Reputation: 9056
It is very basic of PHP. $_POST is super-global array of PHP that stores data that was sent to a particular script using POST method.
You can use it as any other PHP array
Code below will output all the keys of $_POST and corresponding values:
foreach ($_POST as $key => $value) {
echo $key . ' = ' . var_export($value, true);
}
If you know which key you need exactly, you can get it using []
on array like so:
$my_value = $_POST['my_post_field_sent_by_android_app'];
Upvotes: 4