As I need to initialize add headers as global to get headers in all API call, I have tried but while debug its not sending the headers in API call.
val client = OkHttpClient.Builder()
.authenticator { _, response ->
response.request().newBuilder().addHeader(
"authorization","123").build()
}
.connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.build()
AndroidNetworking.initialize(applicationContext, client)
Can you replace your code with mentioned below and try again
OkHttpClient.Builder().add(new Interceptor() {
@Override
public com.squareup.okhttp.Response intercept(Chain chain) throws IOException {
Request.Builder requestBuilder = chain.request().newBuilder();
requestBuilder.header("Content-Type", "application/json");
return chain.proceed(requestBuilder.build());
}
})
.connectTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.build()
AndroidNetworking.initialize(applicationContext, client)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.