當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。