현재 안드로이드를 공부하고있는 학생입니다.
BlogsSearchResults results = null;
try {
String text = URLEncoder.encode(query, "UTF-8");
String apiURL = blogSearchURL + text; // json 결과
apiURL += "&display=" + display + "&start=" + start + "&sort=" + sort;
URL url = new URL(apiURL);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.setRequestProperty("X-Naver-Client-Id", clientId);
con.setRequestProperty("X-Naver-Client-Secret", clientSecret);
int responseCode = con.getResponseCode();
BufferedReader br;
if (responseCode == 200) { // 정상 호출
br = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
} else { // 에러 발생
br = new BufferedReader(new InputStreamReader(con.getErrorStream(), "UTF-8"));
}
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = br.readLine()) != null) {
response.append(inputLine);
}
br.close();
Gson gson = new Gson();
results = gson.fromJson(response.toString(), BlogsSearchResults.class);
} catch (Exception e) {
System.out.println(e);
}
return results;
이런 예제를 만들고있는데 안드로이드 3.0부터는 네트워크사용할때 main thread를 사용하지않게 되있다고 들었습니다. 그래서 구글링으로 찾아보고 공부를하고있는데 이해가 너무 안가서 질문을 남깁니다...
현재 int responseCode = con.getResponseCode() 이 부분에서 catch쪽으로 빠지고,,, html값을 받아와야한다는데 혹시 자세한 설명을 들어주실수있을까요 ?