Dominik wuttke
03/11/2021, 1:00 PMrouting {
authenticate("serveradmin",optional = true) {
get<Server.Connect> {
call.respond("Hello")
}
Client code :
val credentials = Credentials.basic(serverEntity.username,serverEntity.password,Charsets.UTF_8)
val client = OkHttpClient.Builder().build()
val req = Request.Builder().url(serverEntity.serverURL + "/server/status").addHeader("Authorization",credentials).build()
val call = client.newCall(req)
val response = call.execute()
val responseString = response.body?.string() ?: throw IOException()
As a response on mobile I get unauthorized 401, on Web I get the content of the route.
I don't know if this is a problem of Ktor, or if I am doing something wrong by handling the unauthorized response. I tried using an authenticator, make a call without Credentials and respond to the challenge, but this can create an infinite loop of unauthorized.