【发布时间】:2017-03-02 08:00:07
【问题描述】:
如何在 OkHTTP 中捕获超时?是在 onFailure 方法中“调用”的吗?
我想处理互联网连接不良的情况。如果超时,我必须启用一些按钮以允许用户重试。
// Get a handler that can be used to post to the main thread
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
hideDialog();
e.printStackTrace();
// handle timeouts here, enable buttons...
}
【问题讨论】: