繁体   English   中英

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

[英]How to get the request URL for a Retrofit object?

我需要记录翻新创建的请求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());
        }
    });

}

我认为您需要的是http日志拦截器 ,github仓库有一个简单的示例说明如何启动和运行它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM