-
Notifications
You must be signed in to change notification settings - Fork 247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cookie not getting saved when used with kotlin and OKHTTP, while same works for Java and OKHTTPretrofit #36
Comments
I`m sorry I have no info about this problem, If you wish you can track it down and let us know your discoveries |
i got the same problem ...cry!!! |
got the same problem +1 |
I also encountered the same problem in Kotlin |
I've also faced that problem, and in my case it was related to Kotlin object declaration. So if you also using an object as a fabric of Retrofit APIs, you can bypass the issue using object HttpApi {
lateinit private var cookiesHandler: CookieJar
fun updateCookieJarWithContext(context: Context) {
cookiesHandler = PersistentCookieJar(SetCookieCache(), SharedPrefsCookiePersistor(context))
}
private val loggingInterceptor by lazy {
HttpLoggingInterceptor().apply { level = HttpLoggingInterceptor.Level.BODY }
}
private val httpClient by lazy {
OkHttpClient.Builder().apply {
addInterceptor(loggingInterceptor)
cookieJar(cookiesHandler)
}.build()
}
private val builder by lazy { Retrofit.Builder().addConverterFactory(JacksonConverterFactory.create()) }
private fun <ApiInterface> createService(serviceClass: Class<ApiInterface>, apiEndpointUrl: String = "rest") = builder
.baseUrl("https://***/$apiEndpointUrl/")
.client(httpClient)
.build()
.create(serviceClass)
val rest: HttpRestApi by lazy { createService(HttpRestApi::class.java) }
val auth: HttpAuth by lazy { createService(HttpAuth::class.java, "auth") }
} Also I recommend to use a dependency injection framework, like Dagger, there is an example of application context injection. |
@franmontiel why not just have an option to save all cookies regardless if they have |
Hi, I am using kotlin to do my android project. Im using this library on my other java projects on android and all of them works fine. But when I use this with kotlin the cookie is not getting saved. I want to know whether this has occured to you or do you know the work around for this issue?
I have manually checked using adb commands to read the shared prefrences. While on my java project the cokie is being set but here it isnt. Please respond fast
The text was updated successfully, but these errors were encountered: