Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GetUrlContentTask extends AsyncTask<String, Integer, String> {
- protected String doInBackground(String... urls) {
- URL url = null;
- HttpURLConnection connection = null;
- try {
- url = new URL(urls[0]);
- connection = (HttpURLConnection) url.openConnection();
- connection.setRequestMethod("GET");
- connection.setDoOutput(true);
- connection.setConnectTimeout(5000);
- connection.setReadTimeout(5000);
- connection.connect();
- } catch (IOException e) {
- e.printStackTrace();
- }
- BufferedReader rd;
- StringBuilder content = new StringBuilder();
- try {
- assert connection != null;
- rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
- String line;
- while ((line = rd.readLine()) != null) {
- content.append(line).append("\n");
- }
- return content.toString();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return content.toString();
- }
- protected void onProgressUpdate(Integer... progress) {
- }
- protected void onPostExecute(String result) {
- System.out.println("result = " + result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement