0

我现在正在学习 Android,我正在研究如何触发请求并从服务器接收结果。我正在做的是

 // Button Click Event
        btnLogin.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                String      testURL                     =   "http://djs-corner.appspot.com/getClosestClubs?lat=40.7600624&lon=-73.98558";

                // Create http GET method
                HttpClient  client                      =   new DefaultHttpClient();

                // Create http GET method
                HttpGet     getTest                     =   new HttpGet(testURL);

                // Fire a request
                try {
                    HttpResponse response                   =   client.execute(getTest);
                    int statusCode                          =   response.getStatusLine().getStatusCode();
                    HttpEntity entity                       =   response.getEntity();


                    InputStream is                          =   entity.getContent();
                    String      result                      =   convertStreamToString(is);
                    Log.e("RESULT", result);

                } catch (ClientProtocolException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Log.d("ClientProtocolException is ", e.toString());

                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                    Log.d("IOException is ", e.toString());

                }
            }
        });
        String convertStreamToString(InputStream inputStream) throws IOException {
                BufferedReader reader   =   new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
                StringBuilder sb        =   new StringBuilder();

                String line             =   null;
                while ((line = reader.readLine()) != null) 
                     sb.append(line + "\n");         
                return sb.toString();
        }

我得到的结果只是原始结果的一部分。请看这里的图像。如果我们从上面的 url 查看数据,我们可以看到一些数据被砍掉了。我在这里做错了什么。

4

0 回答 0