I\'m trying to use Retrofit2,
I want to add Token to my Header Like this:
Authorization: Bearer Token
but the <
This adds your token to the builder and you can change it at any time in case of login/logout.
object ApiService {
var YOUR_TOKEN = ""
private var retrofit: Retrofit = Retrofit.Builder()
.baseUrl("YOUR_URL")
.addConverterFactory(GsonConverterFactory.create())
.client(OkHttpClient.Builder().addInterceptor { chain ->
val request = chain.request().newBuilder().addHeader("Authorization", "Bearer ${YOUR_TOKEN}").build()
chain.proceed(request)
}.build())
.build()
var service: AppAPI = retrofit.create(AppAPI::class.java)
private set
}