https://kotlinlang.org logo
#ktor
Title
# ktor
p

pascal_le_merrer

09/18/2020, 10:53 AM
Hello. I’m struggling wtih Ktor client auth. I always receive a 401 error with the following code:
Copy code
val client = HttpClient(Apache) {
    install(Auth) {
        followRedirects = true
        basic {
            sendWithoutRequest = true
            username = login
            password = pwd
        }
    }
}
runCatching {
    client.get<HttpResponse>(AUTH_URL)
}.onSuccess {
    client.close()
    print(it.headers)
    return it.status == HttpStatusCode.OK
}.onFailure {
    it.printStackTrace()
    client.close()
    throw it
}
2 Views