小编pra*_*mar的帖子

如何使用Retrofit 2.0获得原始响应和请求

我试图使用Retrofit2.0.2获得原始响应.

到目前为止,我尝试使用以下代码行打印响应,但它打印的地址而不是确切的响应正文.

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);

                }
            });
Run Code Online (Sandbox Code Playgroud)

java android retrofit okhttp retrofit2

17
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×1

java ×1

okhttp ×1

retrofit ×1

retrofit2 ×1