Https的依赖
implementation ‘com.zhy:okhttputils:2.6.2’
object OkHttpManaher {
//这是调用的封装的类
val sslParams = HttpsUtils.getSslSocketFactory(null, null, null)
lateinit var mClient: OkHttpClient
var mFile = File(ComInitCommonNet.sContext!!.getCacheDir(), "child");
fun getClient(): OkHttpClient {
mClient = OkHttpClient.Builder()
.connectTimeout(5000, TimeUnit.MILLISECONDS)
.readTimeout(5000, TimeUnit.MILLISECONDS)
.writeTimeout(5000, TimeUnit.MILLISECONDS)
.cache(Cache(mFile, 1024 * 10))
.addInterceptor(HeadInterception())
//两个方法必写
.hostnameVerifier {hostname, session -> true }
.sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager)
.addInterceptor(HttpLoggingInterceptor(HttpLoggingUtil).setLevel(HttpLoggingInterceptor.Level.BODY))
.build()
return mClient!!
}
}