cor.launch {
val text = Request.getRequest(it)
withContext(cor.coroutineContext) {
textPart.add(text)
}
Log.e("text", "$text")
}
}
suspend fun getRequest(url: String): String? {
delay(30)
var response: HttpResponse? = null
println("url: $url")
try {
response = client.get(url)
println("Server status: ${response.status}")
if (response.status == HttpStatusCode.RequestTimeout) {
println("TIMEOUT: $response")
return null
}
println("RESPONSE: $response")
return response.bodyAsText(Charsets.UTF_8)
} catch (io: IOException) {
if (response != null) {
MKey.serverMessage = "${response.status}"
}
return null
}
}
На Python похоже
Обсуждают сегодня