實現您的自定義OkHttpClientFactory。例如:
public class MyOkHttpClientFactory implements OkHttpClientFactory {
@Override
public OkHttpClient createOkHttpClient() {
long timeout = 30_000;
TimeUnit unit = TimeUnit.MILLISECONDS;
OkHttpClient okClient = new OkHttpClient();
okClient.setConnectTimeout(timeout, unit);
okClient.setReadTimeout(timeout, unit);
okClient.setWriteTimeout(timeout, unit);
return okClient;
}
}
,並設置這個類的一個實例來MobileServiceClient
MobileServiceClient mobileServiceClient = new MobileServiceClient(SERVICE_URL, Context);
mobileServiceClient.setAndroidHttpClientFactory(new MyOkHttpClientFactory());
這對我的作品
爲OkHttpClient默認的超時值是10秒。
客戶端SDK中或服務器執行超時?我確信它正在客戶端上,但它起源於哪裏?你的自定義API做什麼會使它超時 - 發出一個出站HTTP請求? – 2014-09-17 16:16:04