今天开发的时候遇到一个网络请求超时的问题,后台处理是成功的,但是移动端返回的总是提示请求超时,在设置了retrofit请求超时的时间延长以后,就可以请求成功了,下面是配置的方法:
private static final OkHttpClient client = new OkHttpClient.Builder(). connectTimeout(30, TimeUnit.SECONDS). readTimeout(30, TimeUnit.SECONDS). writeTimeout(30, TimeUnit.SECONDS).build(); private <T> T configRetrofit(Class<T> service) { Log.e(TAG, "configRetrofit"); try { retrofit = new Retrofit.Builder() .baseUrl(BuildConfig.MAIN_IP) .client(client) .addConverterFactory(SoapConverterFactory.create()) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .build(); return retrofit.create(service); } catch (Exception e) { LogUtil.e(TAG, "e:" + e); return null; } }