如何在php脚本中获取发布的数据?
我正在开发一个android应用程序,其中我使用以下代码段发布数据如何在php脚本中获取发布的数据?,php,android,Php,Android,我正在开发一个android应用程序,其中我使用以下代码段发布数据 public void postData() { try { // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost
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();
}
}
public void postData()
{
尝试
{
//创建一个新的HttpClient和Post头
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(“http://10.0.2.2/check/justprint.php");
//添加您的数据
List nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“id”,“jaydepsinh jadeja”);
添加(新的BasicNameValuePair(“密码”,“00000000000000”);
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
//执行HTTP Post请求
HttpResponse response=httpclient.execute(httppost);
String text=EntityUtils.toString(response.getEntity());
Log.i(“,”response=“+text”);
}
捕获(客户端协议例外e)
{
Log.e(“错误:,e+”);
e、 printStackTrace();
}
捕获(IOE异常)
{
Log.e(“错误:,e+”);
e、 printStackTrace();
}
}
我的主要要求是在php脚本中获取这些值并显示在网页上。
有没有办法做到这一点?
我想你可以这样做
$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的文件
$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);
}
}