【发布时间】:2018-09-18 19:34:10
【问题描述】:
如何使用Retrofit2/OKHttp3 指定自定义的每个请求的读/写/连接超时?类似的东西
Response<Listings> response =
ApiProvider.getServer1().getListings().setTimeouts(10000).execute();
目前超时设置为 30 秒,这很好,但在一种特定情况下,我受到 10 秒执行限制的约束,我需要确保在此之前获得网络响应。
基于 this nice GitHub comment 我知道我可以使用 @Header 设置自定义超时并在 OKHttp 拦截器中解析它们,但如前所述,我需要在特定上下文中为一个特定 API 调用自定义超时。
我还发现了this answer(选项1)使用 OkHttp 2.2+ 使用拦截器),但我不知道如何告诉拦截器我需要自定义超时。
【问题讨论】:
标签: android retrofit2 okhttp3 connection-timeout