AK
Size: a a a
AK
JR
AK
AK
AK
JR
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Thread queryThread = createHttpTestTask();
queryThread.start();
}
private Thread createHttpTestTask() {
return new Thread(() -> {
try {
String response = execQuery("https://ya.ru");
Log.d("myLogs", response);
} catch (IOException e) {
e.printStackTrace();
}
});
}
private String execQuery(String path) throws IOException {
URL url = new URL(path);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
int status = con.getResponseCode();
if (status != HttpURLConnection.HTTP_OK) {
return null;
}
return convertStreamToString(con.getInputStream());
}
private String convertStreamToString(InputStream stream) throws IOException {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line).append("\n");
}
return sb.toString();
} finally {
stream.close();
}
}
JR
JR
AK
AK
AK
I
I
I
AK
I
I
I
AK
I