我无法从本地服务器android

时间:2015-05-29 08:12:37

标签: android connection localhost

HIII 我正在开发一个Android应用程序,它将学生ID发送到服务器并获取这些学生的信息...... 它在在线服务器上工作正常但我在使用本地服务器时没有得到任何回报...... 当我使用PC或移动浏览器时,我得到了j子阵列,但没有在应用程序中

这是服务器发回的j子阵列

[{"StudentId":"120211001","StudentName":"bilal","StudentSurname":"ahmad","Image":"images\/bila.JPG"}]

这是android代码

    String result = "";
    InputStream isr = null;

    String value = v;
    try {
        DefaultHttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://192.168.1.11/connection/getstudentname.php?codesend=5E3CEB");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity entity = response.getEntity();
        isr = entity.getContent();
    } catch (Exception e) {
        Log.e("log_tag", "Error in http connection " + e.toString());
        resultView.setText("Couldnt connect to database");
    }
    //convert response to string
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(isr, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        isr.close();

        result = sb.toString();
    } catch (Exception e) {
        Log.e("log_tag", "Error  converting result " + e.toString());
    }

    //parse json data
    try {
        String s = "";
        JSONArray jArray = new JSONArray(result);

        for (int i = 0; i < jArray.length(); i++) {
            JSONObject json = jArray.getJSONObject(i);
            s = s +
                    "ID : " + json.getInt("StudentId") + "\n" +
                    "Name : " + json.getString("StudentName") + " " + json.getString("StudentSurname") + "\n\n";


            String nameOfImage = json.getString("image");

        }

        resultView.setText(s);


    } catch (Exception e) {
        // TODO: handle exception
        Log.e("log_tag", "Error Parsing Data " + e.toString());
    }

0 个答案:

没有答案