fix:okhttp自动保存返回的cookie

pull/1852/head
Xwite 3 years ago
parent 872fa8577d
commit 4618b13289
  1. 13
      app/src/main/java/io/legado/app/help/http/HttpHelper.kt

@ -6,6 +6,9 @@ import io.legado.app.help.http.cronet.CronetInterceptor
import io.legado.app.help.http.cronet.CronetLoader import io.legado.app.help.http.cronet.CronetLoader
import okhttp3.ConnectionSpec import okhttp3.ConnectionSpec
import okhttp3.Credentials import okhttp3.Credentials
import okhttp3.CookieJar
import okhttp3.Cookie
import okhttp3.HttpUrl
import okhttp3.Interceptor import okhttp3.Interceptor
import okhttp3.OkHttpClient import okhttp3.OkHttpClient
import java.net.InetSocketAddress import java.net.InetSocketAddress
@ -29,6 +32,16 @@ val okHttpClient: OkHttpClient by lazy {
.writeTimeout(15, TimeUnit.SECONDS) .writeTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS) .readTimeout(15, TimeUnit.SECONDS)
.callTimeout(60, TimeUnit.SECONDS) .callTimeout(60, TimeUnit.SECONDS)
.cookieJar(object : CookieJar {
override fun saveFromResponse(url: HttpUrl, cookies: List<Cookie>) {
cookies.forEach {
CookieStore.setCookie(url.toString(), it.value)
}
}
override fun loadForRequest(url: HttpUrl): List<Cookie> {
return ArrayList<Cookie>()
}
})
.sslSocketFactory(SSLHelper.unsafeSSLSocketFactory, SSLHelper.unsafeTrustManager) .sslSocketFactory(SSLHelper.unsafeSSLSocketFactory, SSLHelper.unsafeTrustManager)
.retryOnConnectionFailure(true) .retryOnConnectionFailure(true)
.hostnameVerifier(SSLHelper.unsafeHostnameVerifier) .hostnameVerifier(SSLHelper.unsafeHostnameVerifier)

Loading…
Cancel
Save