2017-05-09 32 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を変換することはできませんので、あなたが応答を見ることはありません。

String res = new String(responseBody);の代わりに。

問題が解決しない場合は、質問を更新して回答を更新します。

関連する問題