-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetUrl.java
More file actions
50 lines (34 loc) · 1.11 KB
/
Copy pathGetUrl.java
File metadata and controls
50 lines (34 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Gets a single URL synchronously
package com.example.tinyasync;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.StringBuilder;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.HttpURLConnection;
import android.os.AsyncTask;
import android.util.Log;
public class GetUrl {
private static final String TAG = "GetUrl";
public static String hitthepage(String url_name) {
try {
URL url = new URL(url_name);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
BufferedReader result_reader =
new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
StringBuilder result = new StringBuilder();
while ((line = result_reader.readLine()) != null) {
result.append(line).append("\n");
}
return result.toString();
} catch (MalformedURLException e) {
Log.e(TAG,Log.getStackTraceString(e));
} catch (IOException e) {
Log.e(TAG,Log.getStackTraceString(e));
}
return null;
}
}