1

サーバーからデータを取得できません。コードのどこが間違っているのかわかりません。アプリケーションを実行すると、サーバーからのデータがエミュレーターに表示されません。コードを以下に示します。

private void postData1(){


HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost(
        "http://www.xxxxx.co.uk/NottTest/post.php");

JSONObject json = new JSONObject();

try {

    // JSON data:

    try {
        json.put("name", "Fahmi Rahman");
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    json.put("position", "sysdev");

    JSONArray postjson = new JSONArray();

    postjson.put(json);

    // Post the data:

    httppost.setHeader("json", json.toString());

    httppost.getParams().setParameter("jsonpost", postjson);

    // Execute HTTP Post Request

    System.out.print(json);

    HttpResponse response = httpclient.execute(httppost);
    tv.setText("Hiii");

    // for JSON:

    if (response != null)

    {
        Log.i("Json","respose");
        System.out.print("loooooooooool");


        InputStream is = response.getEntity().getContent();

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(is));

        StringBuilder sb = new StringBuilder();

        String line = null;

        try {

            while ((line = reader.readLine()) != null) {

                sb.append(line + "\n");

            }

        } catch (IOException e) {

            e.printStackTrace();

        } finally {

            try {

                is.close();

            } catch (IOException e) {

                e.printStackTrace();

            }

        }

        text = sb.toString();

    }

    else{
        tv.setText("no respose");
        Log.i("Noting","happended");
    }

    //tv.setText(text);

} catch (ClientProtocolException e) {

    Log.i("Error","Prtocol");


} catch (IOException e) {

    Log.i("Error","IO");

} catch (JSONException e) {
    Log.i("Error","JOSON");
}

}

4

1 に答える 1

1

エラーは

try {
        json.put("name", "Fahmi Rahman");
    } catch (JSONException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    json.put("position", "sysdev");

    JSONArray postjson = new JSONArray();
于 2012-07-02T11:39:16.757 に答える