private
class
ExampleThread
extends
Thread {
public
void
run() {
Log.i(
""
,
"run() of ExampleThread object starts."
);
try
{
URL url =
new
URL(
"주소.."
);
InputStream is;
BufferedReader br;
Log.i(
"JSON"
,
"before connection"
);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
Log.i(
"JSON"
,
"after connection"
);
conn.setConnectTimeout(
2000
);
conn.setReadTimeout(
2000
);
conn.setRequestMethod(
"GET"
);
String result =
""
;
Log.i(
"JSON"
,
"before getResponsecode"
);
int
responseCode = conn.getResponseCode();
Log.i(
"JSON"
,
"responseCode + "
+ String.valueOf(responseCode));
if
(responseCode == HttpURLConnection.HTTP_OK) {
Log.i(
"JSON"
,
"enter if"
);
is = conn.getInputStream();
Log.i(
"JSON"
,
"get is"
);
br =
new
BufferedReader(
new
InputStreamReader(is,
"UTF-8"
));
StringBuilder sb =
new
StringBuilder();
while
((result = br.readLine()) !=
null
) {
sb.append(result);
}
String rstr = sb.toString();
Log.i(
"JSON"
, rstr);
}
else
{
Log.i(
"JSON"
,
"enter else"
);
}
}
catch
(MalformedURLException e) {
e.printStackTrace();
}
catch
(IOException e) {
e.printStackTrace();
}
}
}