如何获取改造对象的请求URL?

时间:2018-07-18 08:11:49

标签: android retrofit

我需要记录Retrofit创建的请求URL。我在通过Retrofit生成的Retrofit对象或Web界面上找不到任何getter方法。以下是我的代码,我想在其中记录每个请求的地址:

public void onRequestFoods() {
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(Const.BASE_LOCAL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();
    FoodOrderInterface foodInterface = retrofit.create(FoodOrderInterface.class);
    Log.d(TAG, "onRequestFoods:  request url: ");
    foodInterface.listFoods().enqueue(new Callback<FoodResponse>() {
        @Override
        public void onResponse(Call<FoodResponse> call, Response<FoodResponse> response) {
            List<Food> foods = response.body().getBody().getFoods();
            mPresenter.onResponse((ArrayList<Food>) foods);
        }

        @Override
        public void onFailure(Call<FoodResponse> call, Throwable t) {
            mPresenter.onRequestFailed(t.getMessage());
        }
    });

}

1 个答案:

答案 0 :(得分:0)

我认为您需要的是http logging interceptor,github存储库中有一个简单的示例说明如何启动它并运行