【发布时间】:2013-08-06 11:34:25
【问题描述】:
我创建了一个 http post 请求,用于在 android 中连接 PHP 服务器。 但在服务器端我无法从数组中提取数据
这是发出http请求的代码
List<NameValuePair> pairs = new ArrayList<NameValuePair>(2);
pairs.add(new BasicNameValuePair("time",
String.valueOf(location.getTime())));
pairs.add(new BasicNameValuePair("latitude", new DecimalFormat("#.######").format(location.getLatitude())));
pairs.add(new BasicNameValuePair("longitude",
new DecimalFormat("#.######").format(location.getLongitude())));
pairs.add(new BasicNameValuePair("speed",
String.valueOf(location.getSpeed())));
HttpPost post = new HttpPost(endpoint);
post.setEntity(new UrlEncodedFormEntity(pairs));
在 Eclipse 中,我记录了所有的值。它正在打印 我调试“对”它会打印一个数组
[locations[0][time]=1375788271891,
locations[0][latitude]=12.966116,
locations[0][longitude]=77.638493,
locations[0][speed]=0.0]
在 php 中,我尝试使用
获取此数据 $lat=$_POST["latitude"];
$long=$_POST["longitude"];
$speed=$_POST["speed"];
$time=$_POST["time"];
但我没有得到这些值。有什么问题?有没有人可以帮助我..请回复.. 提前感谢:)
【问题讨论】:
-
@Nirmal 实际上我的问题是 - 从 android 发送的数据是一个数组 location[][]==xxxx 如何从该数组中提取这些数据。那是我的问题
-
尝试跟随桑德斯的回答。您应该将参数转换为 JSON。
-
您能否对您提交的数据进行 var_dump($_POST) 并向我们展示结果。我不认为你可以在不先序列化的情况下发送那种类型的数据
标签: php android arrays http-post