Search in sources :

Example 1 with HostVerifyUtils

use of com.autism.rxsample.utils.rxutils.HostVerifyUtils in project RxSample by Aload.

the class RequestManger method getRetrofit.

/**
     * 获取retrofit对象
     *
     * @param mListener
     * @return
     */
public Retrofit getRetrofit(IBaseRXListener mListener) {
    String url = mListener.getUrl();
    if (null == mRetrofit || !url.equals(mRetrofit.baseUrl().toString())) {
        OkHttpClient.Builder builder = new OkHttpClient.Builder().readTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).addInterceptor(//拦截器处理通用Header
        interceptor).addInterceptor(//日志处理
        loggingInterceptor).connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS).writeTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
        //可以区别http,https
        if (!StringUtil.isNullOrEmpty(url) && url.toLowerCase().contains("https:")) {
            try {
                builder.sslSocketFactory(getSSLSocketFactory(new int[] { mListener.getRawSSl() }));
                builder.hostnameVerifier(new HostVerifyUtils(new String[] { url }));
            } catch (Exception e) {
                mListener.getException(e);
            }
        }
        OkHttpClient client = builder.build();
        mRetrofit = new Retrofit.Builder().client(client).addConverterFactory(GsonConverterFactory.create()).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).baseUrl(url).build();
    }
    return mRetrofit;
}
Also used : OkHttpClient(okhttp3.OkHttpClient) HostVerifyUtils(com.autism.rxsample.utils.rxutils.HostVerifyUtils) IOException(java.io.IOException)

Aggregations

HostVerifyUtils (com.autism.rxsample.utils.rxutils.HostVerifyUtils)1 IOException (java.io.IOException)1 OkHttpClient (okhttp3.OkHttpClient)1