서버에서 특정 PHP 함수를 호출하고 일부 매개 변수를 보내려고합니다. 지금까지는 HttpClient를 사용하여 PHP 파일을 열 수 있고 Json으로 데이터 전송을 실행하고이를 내 앱에서 보여줄 수있었습니다. 이제 특정 기능을 호출하고 매개 변수를 전송할 수있게하려면 어떻게해야합니까 ?? 죄송합니다. 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
}
감사합니다, 늑대.
죄송합니다. – Wolf87