0

I am using a mashable api for cricket scores from devru . The Rest client is working from Post man.When i implemented the same in android to consume API the Json response id incomplete and it is broken in middle of response.

Code:

DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet getRequest = new HttpGet(
        "http://localhost:8080/RESTfulExample/json/product/get");
    getRequest.addHeader("accept", "application/json");

    HttpResponse response = httpClient.execute(getRequest);

    if (response.getStatusLine().getStatusCode() != 200) {
        throw new RuntimeException("Failed : HTTP error code : "
           + response.getStatusLine().getStatusCode());
    }

    BufferedReader br = new BufferedReader(
                     new InputStreamReader((response.getEntity().getContent())));

    String output;
    System.out.println("Output from Server .... \n");
    while ((output = br.readLine()) != null) {
        System.out.println(output);
    }

    httpClient.getConnectionManager().shutdown();

  } catch (ClientProtocolException e) {

    e.printStackTrace();

  } catch (IOException e) {

    e.printStackTrace();
  }

}
ranjit r
  • 25
  • 6
  • try this first of all... http://stackoverflow.com/questions/20713321/httpclient-getconnectionmanager-is-deprecated-what-should-be-used-instead – Paolof76 Feb 02 '15 at 08:50
  • Check the length of response on both sender and receiver side.. System.out.println has limit of about 2000 characters.. it will print that much characters.. you can [this](http://stackoverflow.com/questions/7606077/how-to-display-long-messages-in-logcat) trick to check full data – Ichigo Kurosaki Feb 02 '15 at 08:56

0 Answers0