如何使用OkHttpClient设置日志记录拦截器并进行翻新

时间:2018-01-17 08:39:14

标签: android retrofit2 okhttp3

我基本上想要使用以下两个功能

//记录

HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(logging)
                .build();

//超时

 OkHttpClient client = new OkHttpClient.Builder()
                .connectTimeout(300, TimeUnit.SECONDS)
                .readTimeout(300,TimeUnit.SECONDS).build();

2 个答案:

答案 0 :(得分:1)

只需使用带有拦截器和超时的构建器。

HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient client = new OkHttpClient.Builder()
                        .addInterceptor(logging)
                        .connectTimeout(300, TimeUnit.SECONDS)
                        .readTimeout(300,TimeUnit.SECONDS)
                        .build();

答案 1 :(得分:1)

只需将其添加到那里:

Objective C