【发布时间】:2012-02-26 01:47:55
【问题描述】:
我正在尝试输出我从 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 脚本?
【问题讨论】:
-
你在哪里创建
httppost- 可以请你包括代码吗?您希望在哪里看到 PHP 的输出? -
你的 responseText 是怎么说的?
-
@jsaye 我的回复给了我带有 POST 请求的 HTML 代码,例如" POSTed data: '12345' " 等
-
@ManseUK 我在 "HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("myurl.php");" 正上方创建 httppost,其中 myurl 是我的 php 文件的 url
标签: php android request http-post send