private boolean fetchApp(String url, String username, String password) throws JSONException { try { if (username == "null") { username = null; } if (password == "null") { password = null; } HttpResponse response = makeRequest(url, username, password); StatusLine sl = response.getStatusLine(); int code = sl.getStatusCode(); HttpEntity entity = response.getEntity(); InputStream content = entity.getContent(); if (code != 200) { return false; } else { ZipInputStream data = new ZipInputStream(content); return saveAndVerify(data); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); return false; } }
public String readResponse(HttpResponse response) { String output = ""; HttpEntity entity = response.getEntity(); try { trapException(response.getStatusLine().getStatusCode()); } catch (CrowdFlowerException e1) { e1.printStackTrace(); } InputStream instream; try { instream = entity.getContent(); BufferedReader reader = new BufferedReader(new InputStreamReader(instream)); // do something useful with the response output = output + reader.readLine(); instream.close(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return output; }