This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

executeHttpGet(String)

By: a guest on Nov 8th, 2012  |  syntax: Java  |  size: 0.97 KB  |  views: 72  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public static String executeHttpGet(String requestURL) throws URISyntaxException, ClientProtocolException, IOException {
  2.     BufferedReader in = null;
  3.     String result = "";
  4.     try {
  5.         HttpClient client = new DefaultHttpClient();
  6.         HttpGet request = new HttpGet();
  7.         request.setURI(new URI(requestURL));
  8.         Log.i("requesting", requestURL);
  9.         HttpResponse response = client.execute(request);
  10.         in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
  11.         StringBuffer sb = new StringBuffer("");
  12.         String line = "";
  13.         String NL = System.getProperty("line.separator");
  14.         while ((line = in.readLine()) != null) {
  15.             sb.append(line + NL);
  16.         }
  17.         in.close();
  18.         result = sb.toString();
  19.     } finally {
  20.         try
  21.         {
  22.             in.close();
  23.         }
  24.         catch(NullPointerException e)
  25.         {
  26.             //
  27.         }
  28.     }
  29.     return result;
  30. }
clone this paste RAW Paste Data