Skip to content

Instantly share code, notes, and snippets.

@seccomiro
Last active July 9, 2024 08:15
Show Gist options
  • Save seccomiro/85446c4849855615d1938133bce30738 to your computer and use it in GitHub Desktop.
Save seccomiro/85446c4849855615d1938133bce30738 to your computer and use it in GitHub Desktop.
An adaptation in Kotlin of Rajasekhar's answer at https://stackoverflow.com/a/43366296/1148768
import okhttp3.Interceptor
import okhttp3.Credentials
import okhttp3.Response
import java.io.IOException
class BasicAuthInterceptor(user: String, password: String) : Interceptor {
private val credentials: String = Credentials.basic(user, password)
@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
val request = chain.request()
val authenticatedRequest = request.newBuilder()
.header("Authorization", credentials).build()
return chain.proceed(authenticatedRequest)
}
}
@vtabk2
Copy link

vtabk2 commented Jul 9, 2024

Fatal Exception: java.net.SocketTimeoutException
timeout

BasicAuthInterceptor has more crash time out.
Help me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment