如何在PHP脚本中获取POSTED数据?

时间:2012-03-27 11:24:32

标签: php android

我正在开发一个Android应用程序,我使用以下代码段来发布数据。

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

我的主要要求是在PHP脚本中获取此值并显示在网页上。 有没有办法做同样的事情?

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:0)

我认为你可以像这样得到它们

$id= $_POST['id'];
$password= $_POST['password'];

然后你可以显示它们。如果这不起作用,请尝试

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

并查看是否在该脚本的目录中创建了名为logging.txt的文件