Hello, I've a question. When I click the button, e...
# android
h
Hello, I've a question. When I click the button, encrypted's value changes, but for body isn't changed. Retrofit always saves previous values of encrypted. Is it depend on Retrofit? If yes, how can I clear caches?
Copy code
class RemoteDataSource @Inject constructor() {
        companion object {
           var string: String?=null

            fun setEncr(string: String){
                this.string=string
            }

            fun getEncr():String{
                return this.string!!
            }
       }

       private fun getRetrofitClient( context: Context? = null): OkHttpClient {
        val authenticator:Authenticator?=null

        val encryp= getEncr()
        val  body = "{\r\n\"Data\":\"${encryp}\"\r\n}"
                .toRequestBody("application/json; charset=utf-8".toMediaTypeOrNull())


        return OkHttpClient.Builder()
            .cache(null)
            .addInterceptor { chain ->
                chain.proceed(chain.request().newBuilder().also {
                    it.addHeader("Accept", "application/json")
                    it.method("POST", body)
                }.build())
            }.also { client ->
                authenticator?.let { client.authenticator(it) }
                if (BuildConfig.DEBUG) {
                    val logging = HttpLoggingInterceptor()
                    logging.setLevel(HttpLoggingInterceptor.Level.BODY)
                    client.addInterceptor(logging)
                }
            }.build()
     }
 }
in MainActivity
Copy code
binding.buttonLogin.setOnClickListener {
    val clientId = binding.edittxtClientId.text.toString().trim()
    encrypted = encrypt(clientId, publicKey)
    setStr(encrypted)
    viewModel.loginResponse.observe(this, Observer {

                when (it) {
                    is Resource.Success -> {
                    .....
    }
}
­čśÂ 7