private HttpRequest configure(final HttpRequest request) { request.connectTimeout(TIMEOUT).readTimeout(TIMEOUT); request.userAgent(userAgentProvider.get()); if (isPostOrPut(request)) { // All PUT & POST requests to Parse.com api must be in JSON // https://www.parse.com/docs/rest#general-requests request.contentType(Constants.Http.CONTENT_TYPE_JSON); } return addCredentialsTo(request); }
@Override // 1.data 통신 public ArrayList<String> call() throws Exception { JSONResultString result = null; ArrayList<String> arrayList1 = new ArrayList<String>(); try { HttpRequest request = post("http://192.168.0.5:8088/bitin/api/class/start-attd "); // reiquest 설정 request.connectTimeout(2000).readTimeout(2000); // JSON 포맷으로 보내기 => POST 방식 request.acceptCharset("UTF-8"); request.acceptJson(); request.accept(HttpRequest.CONTENT_TYPE_JSON); request.contentType("application/json", "UTF-8"); // 데이터 세팅 JSONObject params1 = new JSONObject(); params1.put("classNo", classNo); params1.put("startTime", endTime); params1.put("timer", count_timer); Log.d("JoinData-->", params1.toString()); request.send(params1.toString()); // 3. 요청 int responseCode = request.code(); if (HttpURLConnection.HTTP_OK != responseCode) { Log.e("HTTP fail-->", "Http Response Fail:" + responseCode); return null; } else { Log.e("HTTPRequest-->", "정상"); } // 4. JSON 파싱 Reader reader = request.bufferedReader(); // Log.d("Reader",reader); result = GSON.fromJson(reader, JSONResultString.class); reader.close(); // 5. 사용하기 Log.d("---> ResponseResult-->", result.getResult()); // "success"? or "fail"? Log.d("--->Data-->", result.getData().toString()); return result.getData(); } catch (Exception e3) { e3.printStackTrace(); } return result.getData(); }