本文整理汇总了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;
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
示例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;
}
示例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();
}
示例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();
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}