-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI_get.java
More file actions
34 lines (33 loc) · 1.08 KB
/
API_get.java
File metadata and controls
34 lines (33 loc) · 1.08 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
package gachon.mpclass.termprojectmp;
import java.io.IOException;
import java.io.*;
import android.util.Log;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class API_get
{
String result=null;
protected void doInBackground() throws Exception {
try {
URL url = new URL('url');
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
InputStream is = conn.getInputStream();
StringBuilder builder = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
result = builder.toString();
}
catch (Exception e)
{
Log.e("REST_API","GET method failed: "+e.getMessage());
e.printStackTrace();
}
}
}