Logging with Retrofit 2

前端 未结 21 1364
春和景丽
春和景丽 2020-11-22 07:33

I\'m trying to get the exact JSON that is being sent in the request. Here is my code:

OkHttpClient client = new OkHt         


        
21条回答
  •  太阳男子
    2020-11-22 08:03

    for Retrofit 2.0.2 the code is like

       **HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient.Builder httpClient=new OkHttpClient.Builder();
            httpClient.addInterceptor(logging);**
    
    
            if (retrofit == null) {
                retrofit = new Retrofit.Builder()
                        .baseUrl(BASE_URL)
                        .addConverterFactory(GsonConverterFactory.create())
                        **.client(httpClient.build())**
                        .build();
            }
    

提交回复
热议问题