D/OkHttp: --> GET https://example.com:PORT/... http/1.1
    Authorization: Bearer example token
    Device-Type: Android
    --> END GET

我只看到请求信息,但不会收到任何错误/响应。

我使用Retrofit和Okhttp。

配置如下:
private val timeOut: Long = 30 * 1000
private val cacheSize: Long = 10 * 1024 * 1024 // 10 MB
private var cache = Cache(presenterLayer.getCacheDir(), cacheSize)


private val client: OkHttpClient = OkHttpClient.Builder()
        .addInterceptor(RedirectInterceptor())
        .addInterceptor(TokenInterceptor(presenterLayer))
        .addInterceptor(Logger(presenterLayer))
        .cache(cache)
        .sslSocketFactory(CustomTrust.getSSLConfig().socketFactory)
        .followRedirects(false)
        .followSslRedirects(false)
        .connectTimeout(timeOut, TimeUnit.SECONDS)
        .readTimeout(timeOut, TimeUnit.SECONDS)
        .writeTimeout(timeOut, TimeUnit.SECONDS)
        .build()


private val retrofit = Retrofit
        .Builder()
        .baseUrl(presenterLayer.getBaseUrl())
        .client(client)
        .addConverterFactory(GsonConverterFactory.create())
        .build()

我的问题是:除了网络,这什么时候发生?确切发生了什么?

最佳答案

超时的情况下尝试使用TimeUnit.MILLISECONDS,并检查错误请求

private val timeOut: Long = 30 * 1000

.connectTimeout(timeOut, TimeUnit.MILLISECONDS)
.readTimeout(timeOut, TimeUnit.MILLISECONDS)
.writeTimeout(timeOut, TimeUnit.MILLISECONDS)

10-08 18:25