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 に関しては、カーソルを操作した後にデータを受信したり、より具体的にはデータを受信したりしません。その行の前にある echo ステートメントは、Android で受信されます。
助けはありますか?