Kyrremann

Untitled

May 26th, 2015
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.73 KB | None | 0 0
  1. private static String defaultHTTPConnection(String url) {
  2.         HttpClient httpclient = new DefaultHttpClient();
  3.         HttpGet request = new HttpGet();
  4.         URI website;
  5.  
  6.         try {
  7.             website = new URI(url);
  8.             request.setURI(website);
  9.             HttpResponse response = httpclient.execute(request);
  10.             BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
  11.  
  12.             return bufferedReader.readLine();
  13.         } catch (URISyntaxException e) {
  14.             Log.e(TAG, "Can't create URI");
  15.         } catch (ClientProtocolException e) {
  16.             Log.e(TAG, "Something went wrong when connection to client");
  17.         } catch (IOException e) {
  18.             Log.e(TAG, "IOException");
  19.         }
  20.  
  21.         throw new RuntimeException("Could not connect to server");
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment