我想在服務器上調用特定的php函數,併發送一些參數。 直到現在我已經實現了,我可以使用HttpClient打開php文件並執行數據傳輸到Json,並在我的應用程序中顯示。 所以,現在我想能夠調用特定的函數併發送參數給它,我該怎麼做? 對不起,我沒有豪宅,我需要從Android調用該功能。如何從Android調用PHP函數?
這裏的一些代碼:提前
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("http://10.0.2.2/posloviPodaci/index.php");
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection" + e.toString());
}
// Convert response to string
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
sb = new StringBuilder();
sb.append(reader.readLine() + "\n");
String line = "0";
while((line = reader.readLine()) != null){
sb.append(line + "\n");
}
is.close();
result = sb.toString();
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
// Parsing data
JSONArray jArray;
try {
jArray = new JSONArray(result);
JSONObject json_data = null;
items = new String[jArray.length()];
for(int i = 0; i < jArray.length(); i++) {
json_data = jArray.getJSONObject(i);
items[i] = json_data.getString("naziv");
}
} catch (Exception e) {
// TODO: handle exception
}
感謝, 狼。
對不起,我沒有把我正在工作的Andriod應用程序,我想從那裏打電話。 – Wolf87 2012-04-24 16:43:12