Retrofit Post请求无法从服务器获得响应Android
问题描述:
我收到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。
答
什么我假设response.body().toString()
将返回像
ResponseEntity("message":"Posted Successfully","uuid":"5dgiriWE4s4Sqhts")
所以的东西,如果你想,如果你想从中得到你所要做的就像下面uuid
提取例如值(假设你的ResponseEntity
类有getter
和setter
方法)
String udid=(ResponseEntity)(response.body()).getUDID()
希望你会从中得到一个想法。
它是要失败的方法 – Soham
@Soham不,它是一个成功的调用,它只进入onResponse。但是响应没有任何东西,Okhttp拦截器显示在logcat中。 –
ResponseEntity是什么? – Soham