Я выполнил импорт на MainActivity.kt и зависимости в файле build.gradle, я искал ответы.
Код: Выделить всё
class Greeting {
private val client = HttpClient(CIO) {
install(HttpTimeout) {
connectTimeoutMillis = 8000
requestTimeoutMillis = 14000
}
install(Logging) {
logger = Logger.SIMPLE
level = LogLevel.ALL
// filter { request ->
// request.url.host.contains("ktor.io")
// }
// sanitizeHeader { header -> header == HttpHeaders.Authorization }
}
// expectSuccess = true
}
suspend fun greeting(): String {
val httpResponse: HttpResponse = client.get("https://ktor.io/docs/welcome.html")
println("get done")
// val httpResponse: HttpResponse = client.request("https://ktor.io") {
// method = HttpMethod.Get
// }
if (httpResponse.status.value in 200..299) {
println("Successful response!")
}
return "done"
}
}
Код: Выделить всё
val httpResponse: HttpResponse = client.get("https://ktor.io/docs/welcome.html")Я пробовал разные сайты, подтвердил, что есть подключение к Интернету, проверил DNS, чтобы проверить DNS.
Отладка показывает следующее:
Журналы — Logcat
Подробнее здесь: https://stackoverflow.com/questions/791 ... oid-studio
Мобильная версия