Created
September 23, 2015 08:15
-
-
Save MediumOne/72362fe627363531d767 to your computer and use it in GitHub Desktop.
Snippet for HTTPUrlConnection in Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
new Thread() { | |
@Override | |
public void run() { | |
HttpURLConnection urlConnection = null; | |
try { | |
URL url = new URL("http://google.com"); | |
urlConnection = (HttpURLConnection) url.openConnection(); | |
InputStream in = new BufferedInputStream(urlConnection.getInputStream()); | |
//Apache commons IOUtils | |
String result = IOUtils.toString(in); | |
Logger.e(TAG, "result - " + result); | |
} catch (MalformedURLException e) { | |
Logger.e(TAG, "error mfe : " + e.getMessage()); | |
e.printStackTrace(); | |
} catch (IOException e) { | |
Logger.e(TAG, "error io : " + e.getMessage()); | |
e.printStackTrace(); | |
} finally { | |
if(urlConnection != null){ | |
urlConnection.disconnect(); | |
} | |
} | |
} | |
}.start(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment