编写此代码以改进服务生成器:
public class ServiceGenerator {
private static final String BASE_URL = "http://ipaddress:9100/";
private static Retrofit.Builder builder =
new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create());
private static Retrofit retrofit = builder.build();
private static OkHttpClient.Builder httpClient =
new OkHttpClient.Builder()
.connectTimeout(2, TimeUnit.MINUTES)
.readTimeout(5,TimeUnit.MINUTES)
;
public static <S> S createService(
Class<S> serviceClass) {
return retrofit.create(serviceClass);
}
}
但是我在20秒后得到java套接字超时错误,会发生什么?我怎么能解决这个问题呢?谢谢大家。
答案 0 :(得分:0)
你错过了在改装对象中添加你的OkHttpClient.Builder对象:试试这个。
file: