Reputation: 391
I am working on an android application in which I POST data using following code segments.
public void postData()
{
try
{
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://10.0.2.2/check/justprint.php");
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("id", "jaydeepsinh jadeja"));
nameValuePairs.add(new BasicNameValuePair("password", "00000000000000"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
String text = EntityUtils.toString(response.getEntity());
Log.i("","response = "+text);
}
catch (ClientProtocolException e)
{
Log.e("Error:",e+"");
e.printStackTrace();
}
catch (IOException e)
{
Log.e("Error:",e+"");
e.printStackTrace();
}
}
My main requirement is that get this values in php script and display on web page. Is there any way to do the same?
Upvotes: 0
Views: 658
Reputation: 76880
I think thatyou could get them like this
$id= $_POST['id'];
$password= $_POST['password'];
and then you can display them. If this doesn't work, try
$filename = __DIR__.DIRECTORY_SEPARATOR."logging.txt";
if(isset($_POST)){
foreach ($_POST as $key => $value){
file_put_contents($filename, "key[$key] - value[$value] post \n", FILE_APPEND);
}
}
and see if a file called logging.txt is created in the dir of that script
Upvotes: 0
Reputation: 5478
http://php.net/manual/de/reserved.variables.post.php
echo $_POST['id']
Upvotes: 1