【发布时间】:2014-11-22 10:45:55
【问题描述】:
从 android 应用程序,我正在调用我的 php 脚本。
HttpPost httppost = new HttpPost("http://www.smth.net/some.php");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("pa", "555"));
nameValuePairs.add(new BasicNameValuePair("pb", "550"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
}
如何在我的 php 脚本中获取“pa”和“pb”的值。
我做了 $_POST['pa'] 和 urldecode($_POST['pa']) 但这两个都给了我空字符串。
【问题讨论】:
-
您尝试过使用
print_r($_POST)查看发送的内容吗? -
@MarkOrmesher 这会做什么?
-
它将显示存储在
$_POST中的所有内容 - 如果它是空的,那么您就知道问题出在 Android 应用程序中。 -
@MarkOrmesher 是的,它什么也没显示。其他地方出了点问题。我会删除这个问题。或者您可以将此评论作为答案发布,我会接受。
-
已更新。将这两个代码示例留给未来的访问者可能很好,但您决定是否接受任何一个答案:)
标签: php android http-post post-parameter