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); }
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; }
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); }
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(); }
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); }
/** * 设置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; }
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(); }
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(); }
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); }
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); }
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; }
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); }
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); }
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; }
private static void setupRestClient() { String restApiURL = DEV_URL; HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .connectTimeout(30, TimeUnit.SECONDS) .readTimeout(30, TimeUnit.SECONDS) .writeTimeout(30, TimeUnit.SECONDS) .addInterceptor(interceptor).build(); retrofit = new Retrofit.Builder() .baseUrl(restApiURL) .client(client) .addConverterFactory(GsonConverterFactory.create()) .build(); }
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; }
public static <T> T createRetrofitService(final Class<T> clazz, final String endPoint) { // Logs HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); final Retrofit restAdapter = new Retrofit.Builder() .baseUrl(endPoint) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .client(new OkHttpClient.Builder() .addInterceptor(interceptor) .build()) .build(); return restAdapter.create(clazz); }
/** * Method to create a new Retrofit instance * Add the API key {@link MoviesApiInterceptor#intercept(Interceptor.Chain)} * Show debug information only in DEBUG build * * @return Retrofit - used for building API calls */ public static Retrofit buildRetrofit() { OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); httpClient.addInterceptor(new MoviesApiInterceptor()); if (BuildConfig.DEBUG) { HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); httpClient.addInterceptor(loggingInterceptor); } return new Retrofit.Builder() .baseUrl(MOVIEDB_BASE_URL) .client(httpClient.build()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build(); }
@Before public void setUp() { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient() .newBuilder() .addInterceptor(logging) .build(); retrofit = new Retrofit.Builder() .client(client) .baseUrl(URL) .addConverterFactory(XmlRpcConverterFactory.create()) .build(); }
@Inject public HttpHelper() { if (mOkHttpClient == null) { OkHttpClient.Builder builder = new OkHttpClient.Builder(); HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(new HttpLogger()); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); builder.addInterceptor(loggingInterceptor); //设置超时 builder.connectTimeout(10, TimeUnit.SECONDS); builder.readTimeout(20, TimeUnit.SECONDS); builder.writeTimeout(20, TimeUnit.SECONDS); //错误重连 builder.retryOnConnectionFailure(true); mOkHttpClient = builder.build(); } }
@Provides @Singleton OkHttpClient provideOkhttpClient(final Cache cache, final Application application) { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient.Builder client = new OkHttpClient.Builder().addInterceptor(interceptor); client.cache(cache).addInterceptor(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { Request request = chain.request(); // Read from the cache when there is no network if (NetworkUtils.isNetworkAvailable(application)) { request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build(); } else { request = request.newBuilder().header("Cache-Control", "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 7).build(); } return chain.proceed(request); } }); return client.build(); }
public static Retrofit getClient(String url) { if (retrofit==null) { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder() .connectTimeout(6000, TimeUnit.SECONDS) .readTimeout(6000, TimeUnit.SECONDS) .addInterceptor(logging); retrofit = new Retrofit.Builder() .baseUrl(url) .client(okHttpClientBuilder.build()) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build(); } return retrofit; }
@Singleton @Provides public OkHttpClient provideOkHttpClient(HttpLoggingInterceptor loggingInterceptor, @Named("networkTimeoutInSeconds") int networkTimeoutInSeconds, @Named("isDebug") boolean isDebug, Cache cache, @Named("cacheInterceptor") Interceptor cacheInterceptor, @Named("offlineInterceptor") Interceptor offlineCacheInterceptor, @Named("retryInterceptor") Interceptor retryInterceptor) { OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder() .addNetworkInterceptor(cacheInterceptor) .addInterceptor(offlineCacheInterceptor) .addInterceptor(retryInterceptor) .cache(cache) .connectTimeout(networkTimeoutInSeconds, TimeUnit.SECONDS); //show logs if app is in Debug mode if (isDebug) okHttpClient.addInterceptor(loggingInterceptor); return okHttpClient.build(); }
private UserInfoAPI createUserInfoAPI() { HttpLoggingInterceptor logger = new HttpLoggingInterceptor(); logger.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient authClient = new OkHttpClient().newBuilder() .addInterceptor(getAccessTokenInterceptor()) .addInterceptor(logger) .build(); Gson gson = new GsonBuilder().setLenient().create(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(userInfoUrl) .client(authClient) .addConverterFactory(GsonConverterFactory.create(gson)) .build(); return retrofit.create(UserInfoAPI.class); }
private ClientAPI() { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient.Builder client = new OkHttpClient.Builder(); client.addInterceptor(logging); client.addInterceptor(new BearerTokenHeaderInterceptor()); client.addInterceptor(new ErrorInterceptor()); retrofit = new Retrofit.Builder() .baseUrl("http://" + BASE_URL) .addConverterFactory(JacksonConverterFactory.create()) .client(client.build()) .build(); }
private ClientAPI(OAuth2ClientAuthenticationInterceptor basicAuthentication) { HttpLoggingInterceptor logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient.Builder client = new OkHttpClient.Builder(); client.addInterceptor(logging); client.addInterceptor(new ErrorInterceptor()); client.addInterceptor(new BearerTokenHeaderInterceptor()); if (basicAuthentication != null) { client.addInterceptor(basicAuthentication); } retrofit = new Retrofit.Builder() .baseUrl("http://" + BASE_URL) .addConverterFactory(JacksonConverterFactory.create()) .client(client.build()) .build(); }
@Override @Provides @Singleton public OkHttpClient provideOkHttpClient(ApplicationProperties propertiesManager) { HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); if (propertiesManager.logsEnabled()) { loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); } else { loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.NONE); } return new OkHttpClient.Builder() .addInterceptor(loggingInterceptor) .build(); }
public static <T> T create(Class<T> c, String url) { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(interceptor)//日志拦截器 .addNetworkInterceptor(new CommonInterceptor())//网络拦截器,进行重定向等操作 .connectTimeout(10, TimeUnit.SECONDS)//设置连接超时 .build(); Retrofit retrofit = new Retrofit.Builder() .baseUrl(url) .addConverterFactory(XJsonConverterFactory.create())//json数据转换 .addCallAdapterFactory(RxJava2CallAdapterFactory.create())//将Callable接口转换成Observable接口 .client(client)//网络请求客户端为okhttp .build(); return retrofit.create(c); }
@Override @NonNull public OkHttpClient provideOkHttpClient() { Level logLevel = BuildConfig.DEBUG ? Level.BASIC : Level.NONE; HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor().setLevel(logLevel); return new OkHttpClient.Builder() .addInterceptor(loggingInterceptor) .build(); }
private ChuckNorrisApiService getApiService() { HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor(); httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(new BarricadeInterceptor()).addInterceptor(httpLoggingInterceptor).build(); Retrofit retrofit = new Retrofit.Builder().baseUrl(BASE_URL).client(okHttpClient).addConverterFactory(GsonConverterFactory.create()).build(); return retrofit.create(ChuckNorrisApiService.class); }
protected void setLoggingInterceptor(OkHttpClient.Builder clientBuilder) { HttpLoggingInterceptor loggingHeaders = new HttpLoggingInterceptor(); loggingHeaders.setLevel(HttpLoggingInterceptor.Level.HEADERS); clientBuilder.addInterceptor(loggingHeaders); HttpLoggingInterceptor loggingBody = new HttpLoggingInterceptor(); loggingBody.setLevel(HttpLoggingInterceptor.Level.BODY); clientBuilder.addInterceptor(loggingBody); }
public static OkHttpClient create(@NonNull Context context, @NonNull Account account, @NonNull HttpLoggingInterceptor logging) throws InvalidAccountException { OkHttpClient.Builder builder = defaultBuilder(context); // use account settings for authentication AccountSettings settings = new AccountSettings(context, account); builder = addAuthentication(builder, null, settings.username(), settings.password()); // Set logger builder.addInterceptor(logging); return builder.build(); }
@Provides @Singleton @Named("Api") OkHttpClient provideApiClient(OkHttpClient client, HttpLoggingInterceptor loggingInterceptor) { return ApiModule.createApiClient(client) .addInterceptor(loggingInterceptor) .addInterceptor(new StethoInterceptor()) .build(); }
@Provides @Singleton OkHttpClient provideOkHttpClient() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); return new OkHttpClient.Builder().addInterceptor(interceptor).build(); }
private HttpLoggingInterceptor getInterceptor() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); if (debug) { interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); // 测试 } else { interceptor.setLevel(HttpLoggingInterceptor.Level.NONE); // 打包 } return interceptor; }
public static void init(String baseURL, Context context) { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); //OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build(); retrofit = new Retrofit.Builder().baseUrl(baseURL) //.client(client) .client(SelfSigningClientBuilder.createClient(context)) .addConverterFactory(GsonConverterFactory.create()) .build(); }
@Provides @Singleton public OkHttpClient provideOkHttpClient(){ HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build(); return client; }
public static Retrofit getClient() { HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); interceptor.setLevel(HttpLoggingInterceptor.Level.BODY); OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build(); retrofit = new Retrofit.Builder() .baseUrl("http://52.79.134.200") .addConverterFactory(GsonConverterFactory.create()) .addConverterFactory(ScalarsConverterFactory.create()) .client(client) .build(); return retrofit; }
protected void setOkHttpClientDefaults(OkHttpClient.Builder builder) { builder.addNetworkInterceptor(new TheTvdbInterceptor(this)) .authenticator(new TheTvdbAuthenticator(this)); if (enableDebugLogging) { logging = new HttpLoggingInterceptor(); logging.setLevel(HttpLoggingInterceptor.Level.BODY); builder.addInterceptor(logging); } }
private void initOkHttp() { OkHttpClient.Builder client = new OkHttpClient.Builder(); HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); client.addInterceptor(loggingInterceptor); //设置超时 client.connectTimeout(15, TimeUnit.SECONDS); client.readTimeout(20, TimeUnit.SECONDS); client.writeTimeout(20, TimeUnit.SECONDS); //错误重连 client.retryOnConnectionFailure(true); sOkHttp = client.build(); }