簡體   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