retrofit2.HttpException:调用新闻 Api 时显示 HTTP 426 错误

问题描述 投票:0回答:0

我以正确的方式调用 api 但仍然给出 http 426 错误这里是完整的错误

 FATAL EXCEPTION: main Process: com.example.news_api_jetpack_compose, PID: 7437 retrofit2.HttpException: HTTP 426  at retrofit2.KotlinExtensions$await$2$2.onResponse(KotlinExtensions.kt:53) at retrofit2.OkHttpCall$1.onResponse(OkHttpCall.java:161) at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:519) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1137) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:637) at java.lang.Thread.run(Thread.java:1012) Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [androidx.compose.ui.platform.MotionDurationScaleImpl@abdba2b, androidx.compose.runtime.BroadcastFrameClock@9c38e88, StandaloneCoroutine{Cancelling}@2e15021, AndroidUiDispatcher@adf5c46] 2023-05-14 11:02:44.541  7437-7437  Process                 com...mple.news_api_jetpack_compose  I  Sending signal. PID: 7437 SIG: 9

api调用部分

object ApiClient { private const val BASE_URL="https://newsapi.org/v2/" private val retrofit=Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build() val newsApiService:NewsApiService= retrofit.create(NewsApiService::class.java) }

这是我通过的查询 ` var news by remember { mutableStateOf(emptyList()) } val apiKey="21f8e62d9e1c45b49af0a1e373cb619b" 启动效果( key1 = apiKey ){

        val response = ApiClient.newsApiService.getNews(
            query = "tesla",
            from = "2023-01-13",
            sortBy = "publishedAt",
            language = "in",
            apiKey = apiKey
        )
        news = response.articles



}
LazyColumn {
    itemsIndexed(news) { index,article ->
        NewsCard(article)
    }
}

} `

它在一小时前运行完美,但有时它开始给出致命异常改造 http 426 错误

android api kotlin retrofit
© www.soinside.com 2019 - 2024. All rights reserved.