我正在尝试输出从Android手机发送的POST数据,但是我无法在PHP文件中获取任何输出。
这是我的PHP代码:

<?php
  echo "POSTed data: '".$_POST['mydata']."'<br>";
  var_dump($_POST);
?>


这是我的android代码(似乎工作正常)

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("myurl.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("mydata", "12345"));
nameValuePairs.add(new BasicNameValuePair("stringData", "SomeData"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
String responseText = EntityUtils.toString(response.getEntity());
toSendET.setText(responseText);


甚至可以通过电话将POST数据发送到静态PHP脚本吗?

最佳答案

您所拥有的一切正常运行-但是当您在PHP中回显某些内容时,它会回显给调用者-在这种情况下,即浏览器。

如果您在Android上的代码中检查response的值将为POSTed data: '12344'<br>

请参阅PHP中的error_log()函数以登录到文件

07-28 01:13
查看更多