//Запуск фонового потока
new ParseTask().execute("https://www.thingopen.ru/feeds.php?uskey=XXXXXX&basekey=YYYYYYY&results=1");
// Сам поток
private class ParseTask extends AsyncTask {
HttpURLConnection urlConnection = null;
@Override
protected String doInBackground(String... params) {
try {
URL url = new URL(params[0]);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setConnectTimeout(5000);
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
StringBuilder buffer = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
resultJson = buffer.toString();
} catch (Exception e) {
e.printStackTrace();
}
urlConnection.disconnect();
return resultJson;
}
@Override
protected void onPostExecute(String strJson) {
super.onPostExecute(strJson);
// выводим целиком полученную json-строку
Log.e("answer", strJson);
}
}