【发布时间】:2011-09-18 14:45:21
【问题描述】:
我是 Android 新手。我正在尝试制作一个RPC 以从PHP 获取数据并获取JSON 格式。一切都很好,但我没有得到任何数据作为响应。贝娄是我的安卓代码
安卓代码
try{
HttpClient httpClient = new DefaultHttpClient();
JSONObject jsonRequest = new JSONObject();
jsonRequest.put("id", 0);
jsonRequest.put("method", "getData");
HttpEntity entity = new StringEntity(jsonRequest.toString());
HttpPost request = new HttpPost("http://121.247.130.30:8080/test/TestJava.php");
request.setEntity(entity);
HttpResponse response = httpClient.execute(request);
String temp = EntityUtils.toString(response.getEntity());
Log.e("Class====","Error:"+temp);
}
catch(Exception e){
Log.e("Class====","Error:"+e.getMessage());
}
PHP 代码
<?php
class TestJava
{
public function getData()
{
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
echo json_encode($arr);
}
}
?>
如果我在这里做了什么,请告诉我
【问题讨论】: