用php接收android POST数据

用php接收android POST数据,php,android,post,Php,Android,Post,我寻找了一些答案,但什么也找不到。那么,如何使用PHP从android应用程序接收并保存使用POST发送给它的数据呢。我目前正在使用以下代码,因此我将使用什么PHP来存储数据。任何关于这方面的教程链接也会很有帮助 public void send(View v) { // get the message from the message text box String msg = msgTextField.getText().toString(); // make

我寻找了一些答案,但什么也找不到。那么,如何使用PHP从android应用程序接收并保存使用POST发送给它的数据呢。我目前正在使用以下代码,因此我将使用什么PHP来存储数据。任何关于这方面的教程链接也会很有帮助

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();
    }

}
公共作废发送(视图v)
{
//从消息文本框中获取消息
字符串msg=msgTextField.getText().toString();
//确保字段不是空的
如果(msg.length()>0)
{
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(“http://kiwigaming.beastnode.net/upload.php");
试一试{
List nameValuePairs=新的ArrayList(2);
添加(新的BasicNameValuePair(“日期”、“单位编号”);
添加(新的BasicNameValuePair(“Doneornot”,msg));
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
msgTextField.setText(“”;//清除文本框
}捕获(客户端协议例外e){
//TODO自动生成的捕捉块
}捕获(IOE异常){
//TODO自动生成的捕捉块
}
}
其他的
{
//如果文本字段为空,则显示消息
Toast.makeText(getBaseContext(),“所有字段都是必需的”,Toast.LENGTH_SHORT.show();
}
}

超级全局
$\u POST
包含POST数据

<?php
     print_r($_POST);
?>

您需要首先通过替换以下内容获得响应:

httpclient.execute(httppost);
与:

然后你就可以走了

Head[] head = response.getHeaders();
for(int i = 0, i < head.length; i++){
    //find header?
}

那么,这将以什么方式保存数据呢?请解释一下?要访问
Date
变量,例如,在PHP脚本中,您需要
$\u POST['Date']
。关于保存它,这是相当广泛的。根据您的要求,您可以保存到数据库或平面文件中。OP的问题是如何用PHP接收POST数据。对不起,我可能没有把问题说清楚,但我需要PHP代码来组织和保存服务器上的数据。啊,对不起,以为您需要安卓sideNo问题:)安卓是我的事,无论如何,这让我记忆犹新
Head[] head = response.getHeaders();
for(int i = 0, i < head.length; i++){
    //find header?
}
String content = response.getEntity.getContent();