public class HttpUtils { public static String getStringFromHttp(String urlString){ String result = ""; try { URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.connect();; int code = connection.getResponseCode(); if (code == 200){ InputStream is = connection.getInputStream(); result = getStringFromInputStream(is); } } catch (Exception e) { e.printStackTrace(); } return result; } private static String getStringFromInputStream(InputStream is) { String result = ""; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int count = -1; byte[] buffer = new byte[1024]; while ((count = is.read(buffer,0,buffer.length))!=-1){ baos.write(buffer,0,count); baos.flush(); } result = baos.toString(); baos.close(); is.close(); return result; } catch (IOException e) { e.printStackTrace(); } return result; } }