2016-08-19 223 views
0

我收到Log猫中Okhttp Logging拦截器的响应。但是,我无法从通话后的改装回应中得到它。 这是帖子的呼叫:
Retrofit Post请求无法从服务器获得响应Android

private void update(PostEntity postEntity){ 
    Call<ResponseEntity> call = baseProvider.getApiClient(). 
      createNewQuestion(mPrefs.getLoggedUserCityId(), postEntity); 

    call.enqueue(new Callback<ResponseEntity>() { 
     @Override 
     public void onResponse(Call<ResponseEntity> call, Response<ResponseEntity> response) { 
      Log.i("post:", response.body().toString()); 
     } 

     @Override 
     public void onFailure(Call<ResponseEntity> call, Throwable t) { 
      Log.i("Not Working", "Retrofit is not updating the feed!!"); 
     } 
    }); 
} 

d/OkHttp:OkHttp - 发送 - 米利斯:1471598299803
d/OkHttp:OkHttp-收到-米利斯:1471598300522
d/OkHttp:{ “消息”: “成功发布”,“uuid”:“5dgiriWE4s4Sqhts”}

这里我得到了response.body()。toString是可以的。我无法获得okhttp拦截器输出,以便从服务器存储uuid。

+0

它是要失败的方法 – Soham

+0

@Soham不,它是一个成功的调用,它只进入onResponse。但是响应没有任何东西,Okhttp拦截器显示在logcat中。 –

+0

ResponseEntity是什么? – Soham

回答

0

什么我假设response.body().toString()将返回像

ResponseEntity("message":"Posted Successfully","uuid":"5dgiriWE4s4Sqhts") 

所以的东西,如果你想,如果你想从中得到你所要做的就像下面uuid提取例如值(假设你的ResponseEntity类有gettersetter方法)

String udid=(ResponseEntity)(response.body()).getUDID() 

希望你会从中得到一个想法。

+0

这就是问题所在!我可以看到由okhttp日志记录拦截器给出的日志中的响应。但是在改造的回应中,我没有提到任何东西。我得到的回复@ 54393这不是我想要的东西 –

+0

那么你有没有尝试过解决方案? – Soham

+0

@RahulN是你的问题解决? – Soham

相关问题