object OkHttpUtil : KoinComponent {
private val mOkHttpClient: OkHttpClient by inject()
//更新token
fun replaceToken() {
mOkHttpClient.interceptors().filter {
it is BasicParamsInterceptor
}.forEach {
it as BasicParamsInterceptor
it.addHeaderParam(
"token",
RxSPTool.getString(MyApplication.INSTANCE, Const.SP_TOKEN)
)
}
}
//友盟token
fun addDrivenToken(drivenToken:String) {
mOkHttpClient.interceptors().filter {
it is BasicParamsInterceptor
}.forEach {
it as BasicParamsInterceptor
it.addHeaderParam(
"drivenToken",
drivenToken
)
}
}
//更新ScheduleId
fun replaceScheduleId(scheduleId: String) {
mOkHttpClient.interceptors().filter {
it is BasicParamsInterceptor
}.forEach {
it as BasicParamsInterceptor
it.addHeaderParam(
"scheduleId",
scheduleId
)
}
}
}
Koin中OkHttp动态改变header
最新推荐文章于 2023-11-10 16:17:30 发布