Retrofit 2.x : Log Header for request and response

后端 未结 5 1457
傲寒
傲寒 2021-02-13 03:17

I am using retrofit 2.x and i want to log the header and body of request and response .

  HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
            


        
5条回答
  •  -上瘾入骨i
    2021-02-13 03:38

    You need to set following:

       OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
       HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
       httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
       clientBuilder.addNetworkInterceptor(httpLoggingInterceptor);
       clientBuilder.build()
    

提交回复
热议问题