Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.cbrown.myapplication;
- import android.os.AsyncTask;
- import android.util.Log;
- import org.apache.http.HttpEntity;
- import org.apache.http.HttpResponse;
- import org.apache.http.client.methods.HttpGet;
- import org.apache.http.impl.client.DefaultHttpClient;
- import java.io.BufferedReader;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- public class MyTask extends AsyncTask<String, Integer, Long> {
- String jsonString;
- @Override
- protected Long doInBackground(String... strings) {
- String urlString = strings[0];
- DefaultHttpClient httpClient = new DefaultHttpClient();
- HttpGet get = new HttpGet(urlString);
- try {
- HttpResponse response = httpClient.execute(get);
- HttpEntity entity = response.getEntity();
- InputStream inputStream = entity.getContent();
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(inputStream));
- StringBuilder sb = new StringBuilder();
- String line = null;
- while ((line = reader.readLine()) != null) {
- sb.append(line).append("\n");
- }
- jsonString = sb.toString();
- Log.i("holidays", "jsonString=" + jsonString);
- } catch (Exception e) {
- Log.e("holidays", "HTTPClient exception ", e);
- }
- return 0L;
- }
- @Override
- protected void onPostExecute(Long result) {
- Log.i("holidays", "All done, jsonString=" + jsonString);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement