Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- tomcat
- php
- CentOS
- 이클립스
- Android
- 리눅스
- jquery
- input
- error
- Linux
- 와일드카드
- MySQL
- java
- NetBeans
- larravel
- 톰캣
- SeLinux
- ajax
- JSON
- curl
- properties
- html
- DB
- File
- laravel
- 정규식
- junit
- javascript
- Spring
- 안드로이드
Archives
- Today
- Total
합쭈기 programming
http connect - json 본문
protected boolean requestJson(final String addr, final int method, final String data) { if (chkHandler()) { new Thread(new Runnable() { String strJson = ""; @Override public void run() { // TODO Auto-generated method stub try { URL url = new URL(addr); if (url.getProtocol().toLowerCase().equals("http")) { HttpURLConnection httpConn = null; httpConn = (HttpURLConnection) url.openConnection(); httpConn.setConnectTimeout(10000); httpConn.setDoOutput(true); httpConn.setDoInput(true); httpConn.setRequestMethod(methodToString(method)); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(httpConn.getOutputStream())); bw.write(data); bw.flush(); bw.close(); BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getInputStream())); if (httpConn.getResponseCode() == HttpsURLConnection.HTTP_FORBIDDEN) { return; } String data = ""; while ((data = in.readLine()) != null) { if (data != null) strJson += data; } in.close(); httpConn.disconnect(); JSONArray jArr = new JSONArray(strJson); Util.sendMessage(handle, msgWhat, jArr); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block Util.sendMessage(handle, msgError, e.toString()); } catch (ClientProtocolException e) { // TODO Auto-generated catch block Util.sendMessage(handle, msgError, e.toString()); } catch (FileNotFoundException e) { // TODO: handle exception Util.sendMessage(handle, msgError, e.toString()); } catch (IOException e) { // TODO Auto-generated catch blockJSONArray jArr = new JSONArray(strJson); Util.sendMessage(handle, msgError, e.toString()); } catch (JSONException e) { // TODO Auto-generated catch block try { JSONObject jObj = new JSONObject(strJson); Util.sendMessage(handle, msgWhat, jObj); } catch (JSONException e1) { // TODO Auto-generated catch block Util.sendMessage(handle, msgError, e1.toString()); } //Util.sendMessage(handle, msgError, e.toString()); } } }).start(); } else { return false; } return true; }
'Java > Android' 카테고리의 다른 글
스크롤 안에 리스트 (0) | 2015.04.13 |
---|---|
SharedPreferences (0) | 2015.04.13 |
http connect - 파일 업로드 (0) | 2015.04.13 |
hidden keyboard (0) | 2015.04.13 |
fading actionbar 소스 (0) | 2015.04.07 |