我正在从 android 客户端连接到本地 Web 服务器并从 mongodb 数据库中获取结果。
<?php
$Earth_radius = 6378.137; //KM
$required_distance = 20; //KM
if(! isset($_POST['long']) || ! isset($_POST['lat']) )
{
echo 'NOT SET'; //exit();
}
$long = $_POST['lat'];
$lat = $_POST['long'];
// open connection to MongoDB server
$conn = new Mongo('localhost');
// access database
$db = $conn->matabatdb;
// access collection
$collection = $db->matabat;
$center=array($long,$lat);
$radius=$required_distance/$Earth_radius; //convert to radians
echo 'Im Ok here ';
$result = $collection->find(array("loc"=>array('$within'=>array('$centerSphere'=>array($center,$radius)))));
echo ' I can reach here';
var_dump($result->getNext());
echo 'I do not reach this line';
?>
对 $result 的任何操作都不会向 android 客户端提供任何反馈响应
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
if (entity != null) {
String responseText = EntityUtils.toString(entity);
Pattern pattern=Pattern.compile(".*?<body.*?>(.*?)</body>.*?",Pattern.DOTALL);
Matcher matcher=pattern.matcher(responseText);
if(matcher.find()) {
String userID = matcher.group(1).trim();
}
else
Log.i(TAG," POST RESPONSE "+ responseText);
}
else
Log.i(TAG," POST RESPONSE is NULL");
奇怪的是,如果我制作了一个 html 文件并手动发布数据,则代码在浏览器中工作,但对于 android,我在操作光标后没有收到任何数据,或者更具体地说,我没有收到任何数据。在 Android 中接收到该行之前的任何 echo 语句。
有什么帮助吗?