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);
}
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();
}
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);
}
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());
}
});
}
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 {
}
});
}
Aggregations