当前位置: 首页>>代码示例>>Java>>正文


Java HttpLoggingInterceptor类代码示例

本文整理汇总了Java中okhttp3.logging.HttpLoggingInterceptor的典型用法代码示例。如果您正苦于以下问题:Java HttpLoggingInterceptor类的具体用法?Java HttpLoggingInterceptor怎么用?Java HttpLoggingInterceptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpLoggingInterceptor类属于okhttp3.logging包,在下文中一共展示了HttpLoggingInterceptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: retrofit

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
public static Retrofit retrofit() {
    if (mRetrofit == null) {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();

        if (BuildConfig.DEBUG) {
            // Log信息拦截器
            HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
            loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            //设置 Debug Log 模式
            builder.addInterceptor(loggingInterceptor);
        }
        OkHttpClient okHttpClient = builder.build();
        mRetrofit = new Retrofit.Builder()
                .baseUrl(ApiStores2.URL_BASE)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(okHttpClient)
                .build();
    }
    return mRetrofit;
}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:22,代码来源:AppClient2.java

示例2: getDH

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
default DH getDH() {
    Gson gson = NetworkUtilities.getGson();

    OkHttpClient.Builder clientBuilder = NetworkUtilities.getClient(getSatispayContext());
    if (getSatispayContext().enableLog()) {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        clientBuilder.addInterceptor(interceptor);
    }

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(getSatispayContext().getBaseUrl())
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .client(clientBuilder.build())
            .build();

    return retrofit.create(DH.class);
}
 
开发者ID:satispay,项目名称:in-store-api-java-sdk,代码行数:20,代码来源:DHProvider.java

示例3: getClient

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
public static Retrofit getClient() {

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

        if (retrofit==null) {
            retrofit = new Retrofit.Builder()
                    .addCallAdapterFactory(rxAdapter)
                    .baseUrl(BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .client(client)
                    .build();
        }
        return retrofit;
    }
 
开发者ID:lethalskillzz,项目名称:Andela-ALC-Challenge,代码行数:21,代码来源:ApiClient.java

示例4: ApiManager

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
private ApiManager(){
    HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(message -> showRetrofitLog(message)).setLevel(HttpLoggingInterceptor.Level.BODY);//打印请求日志
    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .readTimeout(READ_TIME_OUT, TimeUnit.SECONDS)
            .connectTimeout(CONNECT_TIME_OUT,TimeUnit.SECONDS)
            .addInterceptor(loggingInterceptor)
            .build();
    Retrofit retrofit1 = new Retrofit.Builder()

            .client(okHttpClient)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .baseUrl(Constant.QQ_MUSIC_BASE_URL)
            .build();
    mQQMusicApiService = retrofit1.create(QQMusicApi.class);
}
 
开发者ID:popo1379,项目名称:popomusic,代码行数:17,代码来源:ApiManager.java

示例5: getRetrofit

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
private static Retrofit getRetrofit() {
    HttpLoggingInterceptor logger = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
        @Override
        public void log(@NonNull String s) {
            Log.d("Http", s);
        }
    });

    logger.setLevel(HttpLoggingInterceptor.Level.BODY);

    OkHttpClient client = new OkHttpClient.Builder().addInterceptor(logger).build();

    return new Retrofit.Builder()
            .client(client)
            .baseUrl("http://jsonplaceholder.typicode.com/")
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}
 
开发者ID:GabrielSamojlo,项目名称:OffIt,代码行数:19,代码来源:RestClient.java

示例6: makeOkHttpClientBuilder

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
public static OkHttpClient.Builder makeOkHttpClientBuilder(Context context, @NonNull UserTokenProducer producer) {
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();

    if (BuildConfig.DEBUG) {
        logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    }

    OkHttpClient.Builder builder;
    builder = new OkHttpClient.Builder()
            .addInterceptor(new AuthorizationInterceptor(producer))
            .addInterceptor(new PaginationInterceptor())
            .addInterceptor(new ContentTypeInterceptor())
            .addInterceptor(logging)
            .followRedirects(true)
            .followSslRedirects(true)
            .retryOnConnectionFailure(true)
            .cache(null)
            .connectTimeout(RemoteConstants.TIME_OUT_API, TimeUnit.SECONDS)
            .writeTimeout(RemoteConstants.TIME_OUT_API, TimeUnit.SECONDS)
            .readTimeout(RemoteConstants.TIME_OUT_API, TimeUnit.SECONDS);

    // add cache to client
    final File baseDir = context.getCacheDir();
    if (baseDir != null) {
        final File cacheDir = new File(baseDir, "HttpResponseCache");
        builder.cache(new Cache(cacheDir, 10 * 1024 * 1024)); // 10 MB
    }

    return enableTls12OnPreLollipop(builder);
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:31,代码来源:ServiceFactory.java

示例7: okHttpClient

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
/**
 * 设置okHttp
 *
 * @author ZhongDaFeng
 */
private static OkHttpClient okHttpClient() {
    //开启Log
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor(new HttpLoggingInterceptor.Logger() {
        @Override
        public void log(String message) {
            LogUtils.e("okHttp:" + message);
        }
    });
    logging.setLevel(HttpLoggingInterceptor.Level.BASIC);
    OkHttpClient client = new OkHttpClient.Builder()
            .connectTimeout(CONNECT_TIME_OUT, TimeUnit.SECONDS)
            .writeTimeout(WRITE_TIME_OUT, TimeUnit.SECONDS)
            .readTimeout(READ_TIME_OUT, TimeUnit.SECONDS)
            .addInterceptor(logging)
            .build();
    return client;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:RetrofitUtils.java

示例8: ApiClient

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
private ApiClient() {
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient client = new OkHttpClient.Builder()
            .addInterceptor(interceptor)
            .addInterceptor(new SessionInterceptor())
            //.addInterceptor(new GzipRequsetInterceptor())
            .build();
    OKHttpUtils.cancelCallWithTag(client);
    this.retrofit = new Retrofit.Builder()
            .baseUrl(API_HOST)
            .client(client)
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .build();
}
 
开发者ID:luffyke,项目名称:beegoapix-android-demo,代码行数:17,代码来源:ApiClient.java

示例9: getRetrofit

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
private Retrofit getRetrofit() {

        //http://blog.csdn.net/u014695188/article/details/52985514
        OkHttpClient.Builder builder = new OkHttpClient.Builder();

        builder.connectTimeout(10, TimeUnit.SECONDS);
        builder.readTimeout(10, TimeUnit.SECONDS);
        builder.writeTimeout(10, TimeUnit.SECONDS);

        if (ZKBase.isDebug) {
            //log信息拦截器
            HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
            httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
            //设置Debug Log模式
            builder.addInterceptor(httpLoggingInterceptor);
        }

        return new Retrofit.Builder()
                .baseUrl(Constant.ZKTEAM_DOMAIN_URL)
                .client(builder.build())
                .addConverterFactory(GsonConverterFactory.create(getGson()))
                .build();
    }
 
开发者ID:ZhuoKeTeam,项目名称:JueDiQiuSheng,代码行数:24,代码来源:ZKConnectionManager.java

示例10: Api

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
private Api() {
    HttpLoggingInterceptor logInterceptor = new HttpLoggingInterceptor();
    logInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

    File cacheFile = new File(App.getAppContext().getCacheDir(), "cache");
    Cache cache = new Cache(cacheFile, 1024 * 1024 * 100); //100Mb

    OkHttpClient okHttpClient = new OkHttpClient.Builder()
            .readTimeout(7676, TimeUnit.MILLISECONDS)
            .connectTimeout(7676, TimeUnit.MILLISECONDS)
            .addInterceptor(headInterceptor)
            .addInterceptor(logInterceptor)
            .addNetworkInterceptor(new HttpCacheInterceptor())
            .cache(cache)
            .build();

    Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").serializeNulls().create();

    retrofit = new Retrofit.Builder()
            .client(okHttpClient)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .baseUrl(C.BASE_URL)
            .build();
    service = retrofit.create(ApiService.class);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:Api.java

示例11: createMastodonApi

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
protected void createMastodonApi() {
    mastodonApiDispatcher = new Dispatcher();

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(Spanned.class, new SpannedTypeAdapter())
            .create();

    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    OkHttpClient.Builder okBuilder =
            OkHttpUtils.getCompatibleClientBuilder(preferences)
                    .addInterceptor(new AuthInterceptor(this))
                    .dispatcher(mastodonApiDispatcher);

    if (BuildConfig.DEBUG) {
        okBuilder.addInterceptor(
                new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC));
    }

    Retrofit retrofit = new Retrofit.Builder().baseUrl(getBaseUrl())
            .client(okBuilder.build())
            .addConverterFactory(GsonConverterFactory.create(gson))
            .build();

    mastodonApi = retrofit.create(MastodonApi.class);
}
 
开发者ID:Vavassor,项目名称:Tusky,代码行数:27,代码来源:BaseActivity.java

示例12: getOkHttpClient

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
public static synchronized OkHttpClient getOkHttpClient() {
  if (okHttpClient == null) {
    OkHttpClient.Builder builder = new OkHttpClient.Builder();
    builder.connectTimeout(90, TimeUnit.SECONDS);
    builder.sslSocketFactory(createSSLSocketFactory());
    builder.hostnameVerifier(new HostnameVerifier() {
      @Override public boolean verify(String hostname, SSLSession session) {
        return true;
      }
    });
    if (BuildConfig.DEBUG) {
      // Log信息拦截器
      HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
      loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);//这里可以选择拦截级别

      //设置 Debug Log 模式
      builder.addInterceptor(loggingInterceptor);
    }
    okHttpClient = builder.build();
  }
  return okHttpClient;
}
 
开发者ID:Lingzh0ng,项目名称:ITSM,代码行数:23,代码来源:GlideUtils.java

示例13: BalanceService

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
public BalanceService(HDWallet wallet, String baseUrl) {
    //final RxJavaCallAdapterFactory rxAdapter = RxJavaCallAdapterFactory
    //        .createWithScheduler(Schedulers.io());
    this.client = new OkHttpClient.Builder();
    this.client.addInterceptor(new UserAgentInterceptor());
    this.client.addInterceptor(new SigningInterceptor(wallet));

    final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(new LoggingInterceptor());
    interceptor.setLevel(HttpLoggingInterceptor.Level.BASIC);
    this.client.addInterceptor(interceptor);

    final Moshi moshi = new Moshi.Builder()
                                .add(new BigIntegerAdapter())
                                .build();

    final Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(baseUrl)
            .addConverterFactory(MoshiConverterFactory.create(moshi))
            .client(client.build())
            .build();
    this.balanceInterface = retrofit.create(BalanceInterface.class);
}
 
开发者ID:toshiapp,项目名称:toshi-headless-client,代码行数:23,代码来源:BalanceService.java

示例14: getApiClient

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
private ApiClient getApiClient() {

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

        OkHttpClient myClient = client.build();

        if (BuildConfig.DEBUG) {
            IdlingResources.registerOkHttp(myClient);
        }

        Retrofit retrofit = new Retrofit
                .Builder()
                .baseUrl(BuildConfig.BASE_URL)
                .client(myClient)
                .addConverterFactory(RaveConverterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();
        return retrofit.create(ApiClient.class);
    }
 
开发者ID:iamBedant,项目名称:InstantAppStarter,代码行数:24,代码来源:AppApiHelper.java

示例15: getClient

import okhttp3.logging.HttpLoggingInterceptor; //导入依赖的package包/类
public static Retrofit getClient() {
    if (sRetrofit == null) {
        synchronized (Retrofit.class) {
            if (sRetrofit == null) {
                HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
                interceptor.setLevel(BuildConfig.DEBUG ? HttpLoggingInterceptor.Level.BODY : HttpLoggingInterceptor.Level.NONE);
                OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
                sRetrofit = new Retrofit.Builder()
                        .baseUrl(BuildConfig.BASE_URL)
                        .addConverterFactory(GsonConverterFactory.create())
                        .client(client)
                        .build();
            }
        }
    }
    return sRetrofit;
}
 
开发者ID:graviton57,项目名称:TVGuide,代码行数:18,代码来源:TvApiClient.java


注:本文中的okhttp3.logging.HttpLoggingInterceptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。