Reputation: 2641
I have searched for some answers but I cannot find anything. So how do you use PHP to receive and save the data sent to it using POST from an android app. I am currently using the following code so what PHP would I use to store the data. Any link on tutorials for this would also be helpful.
public void send(View v)
{
// get the message from the message text box
String msg = msgTextField.getText().toString();
// make sure the fields are not empty
if (msg.length()>0)
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://kiwigaming.beastnode.net/upload.php");
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("Date", "Unitnumber"));
nameValuePairs.add(new BasicNameValuePair("Doneornot", msg));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
msgTextField.setText(""); // clear text box
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
else
{
// display message if text fields are empty
Toast.makeText(getBaseContext(),"All field are required",Toast.LENGTH_SHORT).show();
}
}
Upvotes: 1
Views: 2978
Reputation: 20557
You need to get the response first by replacing:
httpclient.execute(httppost);
with:
HttpResponse response = httpclient.execute(httppost);
Then from that you can go
Head[] head = response.getHeaders();
for(int i = 0, i < head.length; i++){
//find header?
}
or get the content?
String content = response.getEntity.getContent();
Upvotes: 0
Reputation: 7243
The superglobal $_POST
contains the post data.
<?php
print_r($_POST);
?>
Upvotes: 3