Created
June 23, 2015 20:09
-
-
Save luctrudeau/3cd09671672c82622e78 to your computer and use it in GitHub Desktop.
HTTPURLConnection
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
AsyncTask<URL, String, String> httpTask = new AsyncTask<URL, String, String>() { | |
@Override | |
protected String doInBackground(URL... urls) { | |
HttpURLConnection urlConnection = null; | |
StringBuilder sb = new StringBuilder(); | |
try { | |
urlConnection = (HttpURLConnection) urls[0].openConnection(); | |
try (BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()))) { | |
for (String line = in.readLine(); line != null; line = in.readLine()) { | |
sb.append(line); | |
} | |
} finally { | |
urlConnection.disconnect(); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return sb.toString(); | |
} | |
@Override | |
protected void onPostExecute(String s) { | |
Log.d("httpTASK", s); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment