String error = ""; // string field private String getDataFromUrl(String demoIdUrl) { String result = null; int resCode; InputStream in; try { URL url = new URL(demoIdUrl); URLConnection urlConn = url.openConnection(); HttpsURLConnection httpsConn = (HttpsURLConnection) urlConn; httpsConn.setAllowUserInteraction(false); httpsConn.setInstanceFollowRedirects(true); httpsConn.setRequestMethod("GET"); httpsConn.connect(); resCode = httpsConn.getResponseCode(); if (resCode == HttpURLConnection.HTTP_OK) { in = httpsConn.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader( in, "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } in.close(); result = sb.toString(); } else { error += resCode; } } catch (IOException e) { e.printStackTrace(); } return result; }