Search in sources :

Example 76 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project toshi-android-client by toshiapp.

the class EthereumService method addLogging.

private void addLogging() {
    final HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(new LoggingInterceptor());
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    this.client.addInterceptor(interceptor);
}
Also used : HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) LoggingInterceptor(com.toshi.manager.network.interceptor.LoggingInterceptor) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Example 77 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project ttdj by soonphe.

the class ApplicationModule method provideOkHttpClient.

@Provides
@Singleton
OkHttpClient provideOkHttpClient() {
    OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS).readTimeout(10, TimeUnit.SECONDS).writeTimeout(10, TimeUnit.SECONDS).retryOnConnectionFailure(true);
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    builder.addNetworkInterceptor(new StethoInterceptor());
    builder.addInterceptor(logging);
    // 请求header拦截器——存在userId/token即添加
    builder.addInterceptor(chain -> {
        Request originalRequest = chain.request();
        if (StringUtils.isEmpty(CacheUtils.getInstance().getString(Constants.USER_ID) + "") || StringUtils.isEmpty(CacheUtils.getInstance().getString(Constants.USER_TOKEN))) {
            return chain.proceed(originalRequest);
        }
        Request authorised = originalRequest.newBuilder().addHeader("userId", CacheUtils.getInstance().getString(Constants.USER_ID).toString()).addHeader("token", CacheUtils.getInstance().getString(Constants.USER_TOKEN) + "").build();
        return chain.proceed(authorised);
    });
    return builder.build();
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) StethoInterceptor(com.facebook.stetho.okhttp3.StethoInterceptor) HttpLoggingInterceptor(com.connxun.ltcx.components.okhttp.HttpLoggingInterceptor) Singleton(javax.inject.Singleton) Provides(dagger.Provides)

Example 78 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project ttdj by soonphe.

the class AppApi method getDynamicAppApi.

/**
 * 动态请求路径+默认json解析
 *
 * @param baseUrl
 */
public AppApiService getDynamicAppApi(String baseUrl) {
    OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(10, TimeUnit.SECONDS).readTimeout(10, TimeUnit.SECONDS).writeTimeout(10, TimeUnit.SECONDS).retryOnConnectionFailure(true);
    HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
    logging.setLevel(HttpLoggingInterceptor.Level.BODY);
    builder.addNetworkInterceptor(new StethoInterceptor());
    builder.addInterceptor(logging);
    Retrofit retrofit = new Retrofit.Builder().client(builder.build()).baseUrl(baseUrl).addCallAdapterFactory(RxJava2CallAdapterFactory.create()).addConverterFactory(GsonConverterFactory.create()).build();
    return retrofit.create(AppApiService.class);
}
Also used : Retrofit(retrofit2.Retrofit) OkHttpClient(okhttp3.OkHttpClient) StethoInterceptor(com.facebook.stetho.okhttp3.StethoInterceptor) HttpLoggingInterceptor(com.connxun.ltcx.components.okhttp.HttpLoggingInterceptor)

Example 79 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project My-MVP by REBOOTERS.

the class RxJavaBaseActivity method withRetrofit2AndGson.

private void withRetrofit2AndGson() {
    final OkHttpClient mClient = new OkHttpClient.Builder().readTimeout(10, TimeUnit.SECONDS).connectTimeout(30, TimeUnit.SECONDS).addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY)).build();
    final Retrofit mRetrofit = new Retrofit.Builder().client(mClient).baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory(RxJava2CallAdapterFactory.create()).build();
    GankApi mGankApi = mRetrofit.create(GankApi.class);
    Observable<GankAndroid> mAndroidObservable = mGankApi.getData("10/1");
    mAndroidObservable.subscribeOn(Schedulers.io()).map(new Function<GankAndroid, GankAndroid.ResultsEntity>() {

        @Override
        public GankAndroid.ResultsEntity apply(GankAndroid gankAndroid) throws Exception {
            return gankAndroid.getResults().get(0);
        }
    }).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<GankAndroid.ResultsEntity>() {

        @Override
        public void accept(GankAndroid.ResultsEntity resultsEntity) throws Exception {
            sb.append(resultsEntity.getCreatedAt()).append("\n").append(resultsEntity.getType()).append("\n").append(resultsEntity.getDesc()).append("\n").append(resultsEntity.getUrl()).append("\n").append(resultsEntity.getWho());
            logContent.setText(sb.toString());
        }
    });
}
Also used : OkHttpClient(okhttp3.OkHttpClient) GankApi(home.smart.fly.http.model.GankApi) Retrofit(retrofit2.Retrofit) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor) GankAndroid(home.smart.fly.http.model.GankAndroid)

Example 80 with HttpLoggingInterceptor

use of okhttp3.logging.HttpLoggingInterceptor in project My-MVP by REBOOTERS.

the class OkHttpCacheActivity method logUse.

private void logUse() {
    HttpLoggingInterceptor mLoggingInterceptor = new HttpLoggingInterceptor();
    mLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    OkHttpClient mClient = new OkHttpClient.Builder().connectTimeout(TIME, TimeUnit.SECONDS).readTimeout(TIME, TimeUnit.SECONDS).writeTimeout(TIME, TimeUnit.SECONDS).addInterceptor(mLoggingInterceptor).build();
    Request mRequest = new Request.Builder().url(BASE_URL).build();
    Call mCall = mClient.newCall(mRequest);
    mCall.enqueue(new Callback() {

        @Override
        public void onFailure(Call call, IOException e) {
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
        }
    });
}
Also used : Response(okhttp3.Response) Call(okhttp3.Call) OkHttpClient(okhttp3.OkHttpClient) Callback(okhttp3.Callback) Request(okhttp3.Request) IOException(java.io.IOException) HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor)

Aggregations

HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)107 OkHttpClient (okhttp3.OkHttpClient)87 Provides (dagger.Provides)27 Retrofit (retrofit2.Retrofit)25 GsonBuilder (com.google.gson.GsonBuilder)24 Singleton (javax.inject.Singleton)24 Cache (okhttp3.Cache)19 Request (okhttp3.Request)16 File (java.io.File)15 Response (okhttp3.Response)15 IOException (java.io.IOException)14 Gson (com.google.gson.Gson)13 Interceptor (okhttp3.Interceptor)11 StethoInterceptor (com.facebook.stetho.okhttp3.StethoInterceptor)6 LoggingInterceptor (com.toshi.manager.network.interceptor.LoggingInterceptor)6 List (java.util.List)5 ErrorInterceptor (me.postaddict.instagram.scraper.interceptor.ErrorInterceptor)5 FakeBrowserInterceptor (me.postaddict.instagram.scraper.interceptor.FakeBrowserInterceptor)5 ResponseBody (okhttp3.ResponseBody)5 BeforeClass (org.junit.BeforeClass)5