首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >有时无法接收到Okhttp的响应

有时无法接收到Okhttp的响应
EN

Stack Overflow用户
提问于 2018-06-17 00:57:32
回答 1查看 157关注 0票数 1
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()

我的问题是:除了网络之外,这种情况发生在什么时候,具体发生了什么?

EN

回答 1

Stack Overflow用户

发布于 2018-06-17 19:15:45

试用timeOutTimeUnit.MILLISECONDS并检查错误请求

private val timeOut: Long = 30 * 1000

.connectTimeout(timeOut, TimeUnit.MILLISECONDS)
.readTimeout(timeOut, TimeUnit.MILLISECONDS)
.writeTimeout(timeOut, TimeUnit.MILLISECONDS)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50889898

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档