我正在嘗試使用Retrofit2.0.2獲取原始響應。如何使用Retrofit 2.0獲取原始響應和請求
到目前爲止,我嘗試使用下面的代碼行打印響應,但它打印的地址,而不是確切的響應正文。
Log.i(「RAW MESSAGE」,response.body()。toString());
compile 'com.squareup.retrofit2:retrofit:2.0.2'
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
GitApi gitApi = retrofit.create(GitApi.class);
Call<Addresses> call = gitApi.getFeed(user);
call.enqueue(new Callback<Addresses>() {
@Override
public void onResponse(Response<Addresses> response, Retrofit retrofit) {
try {
mDisplayDetails.setText(response.body().getSuburbs().get(0).getText());
**Log.i("RAW MESSAGE",response.body().toString());**
} catch (Exception e) {
mDisplayDetails.setText(e.getMessage());
}
mProgressBar.setVisibility(View.INVISIBLE);
}
@Override
public void onFailure(Throwable t) {
mDisplayDetails.setText(t.getMessage());
mProgressBar.setVisibility(View.INVISIBLE);
}
});
的可能的複製[改裝2.0b2:如何從響應得到的InputStream(HTTP:/ /stackoverflow.com/questions/33030137/retrofit-2-0b2-how-to-get-inputstream-from-the-response) –
的人來到這裏,完整的答案可以在這裏找到:http://stackoverflow.com/問題/ 21398598/how-to-post-raw-whole-json-in-the-the-body-of-a-retrofit-request/36821182#36821182 – TommySM