Logging with Retrofit 2

前端 未结 21 1599
春和景丽
春和景丽 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 07:53

    A best way to do this right in Retrofit 2 is to add the logger interceptor as a networkInterceptor this will print out the network headers and your custom headers too. The important thing is to remember that interceptor work as a stack and be sure u add the logger at the end of all.

    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.addInterceptor(new MyCustomInterceptor());
    builder.connectTimeout(60, TimeUnit.SECONDS);
    builder.readTimeout(60, TimeUnit.SECONDS);
    builder.writeTimeout(60, TimeUnit.SECONDS);
    // important line here
    builder.addNetworkInterceptor(LoggerInterceptor());
    

提交回复
热议问题