0

I am learning Android now and I am working on how to fire a request and receive a result from server. What I am doing is

 // 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();
        }

The result I am getting back is just partial of original result.Please look at the image at here. If we take a look at data from the above url, we can see that some of the data are chopped down. What i am doing wrong at here.

Valery Viktorovsky
  • 6,487
  • 3
  • 39
  • 47
tranvutuan
  • 6,089
  • 8
  • 47
  • 83
  • 1
    It's probably not (only giving you a partial result)! Try writing the response to a file and see! I get caught out by this one. DDMS only logs *n* lines ( I forget how many!). It's a compiled in constant- if you want the lot, you'll have to build ddms yourself. So basically, I see no problems with your code, it's probably the logger, and yes, it's *really* annoying! Good luck learning android! – Tom May 01 '13 at 17:33
  • How many responses are you expecting back from the web service? You should only be getting partial results, getting every single entry in the db could be dangerous and time consuming. – yams May 01 '13 at 17:47
  • thanks all you guys for your responses. – tranvutuan May 02 '13 at 14:03

0 Answers0