2017-05-09 1 views
0

서버에 JSON을 게시해야하며 서버가 다른 서버를 검색해야합니다. 나는 이것을 시도했지만 효과가 없다. 디버그 할 때 성공 또는 실패에 대한 로그가 표시되지 않습니다.AsyncHttpClient 게시 및 JSON 응답 받기

 String url = "https://*******/sessions"; 


     JSONObject requestObject = new JSONObject(); 
     try { 
      requestObject.put("company", "TEST"); 
      requestObject.put("user", "*****"); 
      requestObject.put("secure_password", "8ce241e1ed84937ee48322b170b9b18c2"); 
      requestObject.put("secure_device_id", "C4CA4238A0B923820DCC509A6F75849B"); 
     } catch (JSONException e) { 
      e.printStackTrace(); 
     } 


//  JSONObject jsonParams = new JSONObject(); 
//  jsonParams.put("notes", "Test api support"); 
     StringEntity entity = null; 
     try { 
      entity = new StringEntity(requestObject.toString()); 
     } catch (UnsupportedEncodingException e) { 
      e.printStackTrace(); 
     } 
     entity.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json")); 
     client.post(this, url, entity, "application/json", 
       new AsyncHttpResponseHandler() { 
        @Override 
        public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) { 
         String res = responseBody.toString(); 
         Log.e("response " , res); 
        } 

        @Override 
        public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) { 

        } 
       }); 

응답 본문은 어떻게 얻을 수 있습니까?

+0

당신이 지금 무엇을 얻을 수 있는지 말해야합니다. 나는 당신이 그것을 실제로 잘못한 것을 볼 수 있습니다. – greenapps

답변

0

난 당신이 요구하는 것을 명확하게 이해하지 않지만, 당신이 String res = responseBody.toString(); 같은 문자열에 reponseBody을 변환 할 수 없기 때문에 당신이 응답을 표시하지 않습니다.

do대신에.

문제가 아닌 경우 질문을 업데이트하면 답변이 업데이트됩니다.